8

I have a .vtk file at remote server. I am accessing it via http (I verified that the url of the file is correct, in fact I can download it from the browser). I've also tried to remove the blank spaces from the file as suggested in xtk volume rendering with .vtk file created from matlab.

But i get an exception

Unable to get property 'length' of undefined or null reference.

Can you please guide me the .vtk file format that should be used in order to make it work smoothly ? I am following the xtk tutorial http://jsfiddle.net/gh/get/toolkit/edge/xtk/lessons/tree/master/05/#run, below is my code

window.onload = function () {

    // create and initialize a 3D renderer
    var r = new X.renderer3D();
    r.init();

    // create a new X.mesh
    var skull = new X.mesh();
    // .. and associate the .vtk file to it
     skull.file = 'http://localhost/startup/bunnycheck.vtk';  //using other .vtk file
    //skull.file = 'http://x.babymri.org/?skull.vtk';     

    // .. make it transparent
    skull.opacity = 0.5;

    // .. add the mesh
    r.add(skull);

    // re-position the camera to face the skull
    r.camera.position = [0, 400, 0];

    // animate..
    r.onRender = function () {
         r.camera.rotate([1,0]);
    };

    r.render();

};
Community
  • 1
  • 1
AkshayJ
  • 771
  • 6
  • 15
  • You can see my edited question :)..the .vtk file being too large in size I am not uploading it here... – AkshayJ Nov 23 '15 at 04:54
  • Yes I can download the file specified correctly...I am getting this exception in the xtk.js library which I am using to render.Besides i have also removed all the blank spaces in .vtk file as suggested by some of the geeks here... – AkshayJ Nov 23 '15 at 09:07
  • I don't have much experience with xtk, I am afraid you will have to debug into the library (start by analyzing the call stack of the exception, from example from the "developers tools" of chrome) – lib Nov 23 '15 at 09:12
  • Debugging the library is my last possible option though :(....I can get to work the demo skull.vtk file shown in the xtk library example... – AkshayJ Nov 23 '15 at 09:19

2 Answers2

2

I just got a similar exception, the problem was that the file was a binary vtk file, and it should have been ASCII .

lib
  • 2,918
  • 3
  • 27
  • 53
  • 1
    Since it was only 1 file, I just opened it in Paraview, then choose the correct flag when saving it again. Otherwise you can use the VTK api and in the writer remember to call SetFileTypeToASCII () – lib Dec 02 '15 at 10:35
  • How to call SetFileTypeToASCII() in VTK api??I have no idea? – AkshayJ Dec 02 '15 at 11:08
  • http://www.vtk.org/Wiki/VTK/Examples/Cxx#Input_and_Output , but then I suggest you just to stick with a GUI program like paraview or slicer if you are not already usign the vtk api – lib Dec 02 '15 at 11:12
  • # vtk DataFile Version 3.0 vtk output ASCII DATASET POLYDATA POINTS 98 float.......Is the header of my vtk file which indicates its already in ASCII :( – AkshayJ Dec 02 '15 at 12:17
  • :What might be the issue now? :( – AkshayJ Dec 03 '15 at 04:36
  • Where does your file come from? I would open the file in paraview, look at the info (number of points, number of cells), try to apply decimation or cleaning or triangulation and save it again until it works... – lib Dec 03 '15 at 09:18
  • Let us [continue this discussion in chat](http://chat.stackoverflow.com/rooms/96864/discussion-between-akshayj-and-lib). – AkshayJ Dec 03 '15 at 09:20
  • Switching to Ascii VTK fixed this issue for me. Just a note, if you are using 3D Slicer, you can also save vtk in either binary or ascii - it defaults to binary, but when you are in the save dialog if you click "Show Options" you can un-check "Compress", which renders Ascii. – Guy Starbuck Dec 19 '18 at 22:56
0

You should notice the version of vtk.

As far as I know, xtk cannot support vtk9.0.1, because the vtk format changed a lot in vtk9.0.1.
You can revert to vtk version 8.1.2 or older.

SherylHohman
  • 16,580
  • 17
  • 88
  • 94