[vtkusers] Creating Curved MPR Image

Eyal Ben-Ishai eyalbi007 at gmail.com
Thu Sep 15 05:05:56 EDT 2011


Dear Peter,

Yes a ran it in release mode. In debug it took 8(!!!) seconds.
As for the vtkStructuredGrid - can you assist in how exactly to build it? I
tried the following code:


   // Create the structured grid.
   vtkStructuredGrid *sgrid = vtkStructuredGrid::New();
   sgrid->SetDimensions(dims);

   vtkPoints *points = vtkPoints::New();
   points->Allocate(dims[0]*dims[1]);

   // READ POINTS FROM TEXT FILE
   string line;
   ifstream myfile;

myfile.open("D:\\RCADIA\\Eyal\\VTK_Learning\\LearnVTK\\StructuredGrid1\\grid1.txt");
   if (myfile.is_open())
   {
    //while (!myfile.eof())
    for (j=0; j<dims[1]; j++) // Go over Y's
    {
     jOffset = j * dims[0];
     for (i=0; i<dims[0]; i++) // Go over X's
     {
      offset = i + jOffset;
      getline(myfile, line);
      x[0] = atof(line.c_str());
      getline(myfile, line);
      x[1] = atof(line.c_str());
      getline(myfile, line);
      x[2] = atof(line.c_str());
      points->InsertPoint(offset,x);
     }
    }
    myfile.close();
   }
   else
    cout << "Unable to open file";

  sgrid->SetPoints(points);
  points->Delete();
However I think the grid's topology is still incorrect since it only has
points while what I'm looking for is more of a mesh.

Thank you,
Eyal.

On Thu, Sep 15, 2011 at 10:55 AM, Peter Maday <madapeti at gmail.com> wrote:

> Dear Eyal,
>
> I believe using vtkStructuredGrid should be applied for the sampling
> instead of vtkPolyData as it has a regular grid topology, so that
> there is a direct correspondence between the cells and the image
> pixels, while vtkPolyData does not have such a structure. I do not
> know how to convert the resulting vtkUniformGrid to an image that can
> be visualized in vtk, but it seems more reasonable for me to approach
> this way. I guess you should find some examples about rendering images
> in general in tutorial examples. To be honest I am currently trying to
> investigate the same speed issues with vtkProbeFilter (in 3D). Anyway
> I don't think it should take half a second to do the sampling, as
> there are volume slicer widgets that run at interactive frame rates
> and do basically the same thing. By the way are you using the release
> version of the VTK library? For me at least cmake is compiling for
> debug as default (yielding <dll/so name>D.<dll/so> that should be much
> slower than the release build.
>
> Peter
>
> 2011/9/15 Eyal Ben-Ishai <eyalbi007 at gmail.com>:
>  > Thank you for your reply! Yes I have tried using the vtkProbeFilter,
> this is
> > the code:
> >
> >   //Read volume
> >   std::string inputFilename = "volume.mhd";
> >   vtkSmartPointer<vtkMetaImageReader> reader =
> > vtkSmartPointer<vtkMetaImageReader>::New();
> >   reader->SetFileName(inputFilename.c_str());
> >   reader->Update();
> >
> >   // Read points
> >   std::string filename = argv[1];
> >   std::ifstream fin(filename.c_str());
> >
> >   std::string line;
> >   vtkSmartPointer<vtkPoints> points = vtkSmartPointer<vtkPoints>::New();
> >   while(std::getline(fin, line))
> >   {
> >     double x,y,z;
> >     std::stringstream linestream;
> >     linestream << line;
> >     linestream >> x >> y >> z;
> >
> >     points->InsertNextPoint(x, y, z);
> >   }
> >
> >   fin.close();
> >
> >   // Polydata
> >   vtkSmartPointer<vtkPolyData> polydata =
> > vtkSmartPointer<vtkPolyData>::New();
> >   polydata->SetPoints(points);
> >
> >   // Probe Filter
> >   vtkSmartPointer<vtkProbeFilter> probe =
> > vtkSmartPointer<vtkProbeFilter>::New();
> >   probe->SetSource(reader->GetOutput());
> >   probe->SetInput(polydata);
> >   probe->Update();
> >
> > Regarding this code, I have 3 questions (other than "is it correct?" of
> > course):
> >
> > 'points' are the points to sample the volume at. There are 10,000
> sampling
> > points that should output a 100x100 2D image. However, I didn't use this
> > information anywhere which is probably incorrect since 10,000 points can
> > also produce 50x200 2D image. How should it be done?
> > How can I render the resulted 2D image?
> > The probing ('probe->Update()') takes quite a lot of time (~400ms), while
> I
> > need this action to be much faster since it's intended to be interactive.
> > How can I speed things up? Maybe using vtkStructuredGrid will be faster?
> >
> > Thank you so much,
> > Eyal.
> >
> >
> > On Wed, Sep 14, 2011 at 2:25 PM, peterm <madapeti at gmail.com> wrote:
> >>
> >> Hello
> >>
> >> Did you try using the vtkProbeFilter for sampling from the grayscale
> >> volume?
> >> You can find some examples about probing along lines and planes in the
> VTK
> >> example code.
> >>
> >> --
> >> View this message in context:
> >>
> http://vtk.1045678.n5.nabble.com/Creating-Curved-MPR-Image-tp4802388p4802571.html
> >> Sent from the VTK - Users mailing list archive at Nabble.com.
> >> _______________________________________________
> >> Powered by www.kitware.com
> >>
> >> Visit other Kitware open-source projects at
> >> http://www.kitware.com/opensource/opensource.html
> >>
> >> Please keep messages on-topic and check the VTK FAQ at:
> >> http://www.vtk.org/Wiki/VTK_FAQ
> >>
> >> Follow this link to subscribe/unsubscribe:
> >> http://www.vtk.org/mailman/listinfo/vtkusers
> >
> >
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.vtk.org/pipermail/vtkusers/attachments/20110915/4019da12/attachment.htm>


More information about the vtkusers mailing list