[vtkusers] some questions about cells, file formats, etc
David Doria
daviddoria at gmail.com
Wed Jan 11 15:15:57 EST 2012
On Wed, Jan 11, 2012 at 3:04 PM, nuno.jf <nunofernandes7 at gmail.com> wrote:
> Sure, and thank you for your help!
> Sorry for some confusion in my code:
> (Btw, I noticed that When I set mc->ComputeNormalsOff() instead of
> mc->ComputeNormalsOn() , I don't get this error)
>
>
>
> // Includes for lots of things
> //VTK
> #include "vtkSmartPointer.h"
> #include "vtkPolyData.h"
> #include "vtkPolyDataReader.h"
> #include "vtkStructuredPointsReader.h"
> #include "vtkMarchingCubes.h"
> #include "vtkImageMarchingCubes.h"
> #include "vtkGaussianSplatter.h"
> #include "vtkImageGaussianSmooth.h"
> #include "vtkPolyDataConnectivityFilter.h"
> #include "vtkContourFilter.h"
> #include "vtkGaussianSplatter.h"
> #include "vtkPolyDataWriter.h"
> #include "vtkGeometryFilter.h"
> #include "vtkStructuredPoints.h"
> #include "vtkThreshold.h"
> //renderização
> #include "vtkPolyDataMapper.h"
> #include "vtkActor.h"
> #include "vtkRenderer.h"
> #include "vtkRenderWindow.h"
> #include "vtkRenderWindowInteractor.h"
> #include "vtkImageSobel3D.h"
>
> #include "vtkXMLPolyDataWriter.h"
>
> // main function
>
> int main( int argc, char *argv[] )
> {
>
> vtkStructuredPointsReader *imp1 = vtkStructuredPointsReader::New();
> imp1 -> SetFileName( argv[1] );
> imp1 -> Update();
>
> vtkImageGaussianSmooth *smooth = vtkImageGaussianSmooth::New();
> smooth->SetInput(imp1->GetOutput());
> smooth->SetDimensionality(3);
> smooth->SetStandardDeviations(1,1,1);
> smooth->Update();
>
>
> vtkSmartPointer<vtkImageMarchingCubes> mc =
> vtkSmartPointer<vtkImageMarchingCubes>::New();
> mc->SetInput(smooth->GetOutput());
> mc->ComputeNormalsOn();
> mc->ComputeScalars();
> mc->ComputeGardientsOn();
> mc->GenerateValues(1,atof(argv[2]),atof(argv[3]));
> mc->Update();
>
> vtkSmartPointer<vtkRenderer> renderer =
> vtkSmartPointer<vtkRenderer>::New();
> renderer->SetBackground(.1, .2, .3);
>
> vtkSmartPointer<vtkRenderWindow> renderWindow =
> vtkSmartPointer<vtkRenderWindow>::New();
> renderWindow->AddRenderer(renderer);
> vtkSmartPointer<vtkRenderWindowInteractor> interactor =
> vtkSmartPointer<vtkRenderWindowInteractor>::New();
> interactor->SetRenderWindow(renderWindow);
>
> vtkSmartPointer<vtkPolyDataMapper> mapper =
> vtkSmartPointer<vtkPolyDataMapper>::New();
> mapper->SetInputConnection(mc->GetOutputPort()); //mc->GetOutputPort()
>
> vtkSmartPointer<vtkActor> actor = vtkSmartPointer<vtkActor>::New();
> actor->SetMapper(mapper);
>
> renderer->AddActor(actor);
>
> renderWindow->Render();
> interactor->Start();
>
> vtkPolyData * out = vtkPolyData::New();
> out = mc->GetOutput();
> out ->Update();
>
> //Writer
> vtkPolyDataWriter *writer =vtkPolyDataWriter::New();
> writer ->SetInput(out);
> writer->SetFileTypeToASCII();
> writer ->SetFileName("output.vtk");
> writer ->Update();
>
> //XML Writer
>
> vtkXMLPolyDataWriter * writer2 = vtkXMLPolyDataWriter::New();
> writer2->SetInput(out);
> writer2->SetDataModeToAscii();
> writer2->SetFileName("outputXML.vtp");
> writer2->Update();
>
>
>
> }
Unfortunately I don't know the answer to your question. However, some tips:
This is wrong:
vtkPolyData * out = vtkPolyData::New();
out = mc->GetOutput();
out ->Update();
You are creating a new 'out' object, but then changing the pointer to
the output of 'mc'. You should simply do:
vtkPolyData * out = mc->GetOutput();
Also, you should always use the SetInputConnection/GetOutputPort (or
GetProducerPort) rather than SetInput/GetOutput pair. It is just the
"new" thing to do.
Change:
vtkPolyDataWriter *writer =vtkPolyDataWriter::New();
writer ->SetInput(out);
to
vtkPolyDataWriter *writer =vtkPolyDataWriter::New();
writer ->SetInputConnection(out->GetProducerPort());
GetOutputPort is for filter, GetProducerPort is for objects (like vtkPolyData).
I suggest you start a new thread with your new problem, as the current
title is not very indicative of the problem.
David
More information about the vtkusers
mailing list