[vtkusers] Weird vtkClipPolyData error when using an *.obj
Adam R. Gerlach
agerlach at gmail.com
Thu May 19 16:27:13 EDT 2011
Thanks,
I realized my problem now. I was doing tracer -> vtkSelectPolyData ->
vtkClipPolyData. But the output of vtkSelectPolyData is already what I
needed. It just so happen to work with the .ply because it has scalar
data for the color at each pixel while the obj relies on texture
mapping. I thought the vtkSelectPolydata worked by outputing the
original polydata with a boolean scalar that indicated what points were
selected, but it actually extracts the selected polydata.
Thank you very much!
Adam
On 5/19/2011 3:32 PM, Jérôme wrote:
> Hi,
>
> If you want to track the bug, you should avoid a so complicated code
> (I got some
> build error, I don't know if my fixes are coherent with your
> issue...). The error
> message deals with Clip, so basically you write a test pipeline like
> this :
> reader -> clip -> update
> If the error doesn't occur, add and test new functionnality step by step.
>
> For your case, I just opened your data with paraview : it seems that
> your obj file
> doesn't contain point data. Please, try to generate scalar data before
> clipping,
> as the error says.
>
> Jerome
>
> 2011/5/19 agerlach <agerlach at gmail.com <mailto:agerlach at gmail.com>>
>
> OK. Here is an attempt at an example of my problem. Unfortunately
> for some
> reason I cannot get an observer to work to identify the end of the
> tracerWidet event. I'm sure it is something simple. So, may need
> some help
> getting that to work before I will be able to demonstrate my problem.
> (Please be patient, I'm a newbie) In my main application it uses a
> gui so I
> use the gui button press to turn tracerWidet off and then compute
> the area.
>
> To run place the following ply and obj model and texture in the
> same folder
> as the exe.
> http://www.intellimedsystems.com/files/AreaTruth_T1.jpg Texture
> http://www.intellimedsystems.com/files/AreaTruth.ply ply model
> http://www.intellimedsystems.com/files/AreaTruth.obj obj model
>
> Run and type y to use the obj otherwise the ply will be loaded.
>
> #include <vtkPolyDataMapper.h>
> #include <vtkActor.h>
> #include <vtkRenderWindow.h>
> #include <vtkRenderer.h>
> #include <vtkRenderWindowInteractor.h>
> #include <vtkPolyData.h>
> #include <vtkSmartPointer.h>
> #include <vtkSphereSource.h>
> #include <vtkImageTracerWidget.h>
> #include <vtkInteractorStyleTrackballCamera.h>
> #include <vtkSelectPolyData.h>
> #include <vtkClipPolyData.h>
> #include <vtkMassProperties.h>
> #include <vtkPLYReader.h>
> #include <vtkOBJReader.h>
> #include <vtkJPEGReader.h>
> #include <vtkTexture.h>
> #include <vtkCallbackCommand.h>
>
>
> class vtkITWCallback : public vtkCommand
>
> {
>
> public:
> static vtkITWCallback *New()
> { return new vtkITWCallback; }
>
> virtual void Execute(vtkObject *caller, unsigned long, void*)
> {
> vtkImageTracerWidget *tracer =
> reinterpret_cast<vtkImageTracerWidget*>(caller);
>
> if(tracer->IsClosed()) {
> vtkSmartPointer<vtkPolyData> tracePolyData =
> vtkSmartPointer<vtkPolyData>::New();
>
> tracer->GetPath(tracePolyData);
> std::cout << "There are " <<
> tracePolyData->GetNumberOfPoints()
> << " points in the path." << std::endl;
>
> vtkSmartPointer<vtkSelectPolyData> loop =
> vtkSmartPointer<vtkSelectPolyData>::New();
> loop->SetInput(polyData);
> loop->SetLoop(tracePolyData->GetPoints());
> loop->SetSelectionModeToSmallestRegion();
> loop->Update();
>
> vtkSmartPointer<vtkClipPolyData> clip =
> vtkSmartPointer<vtkClipPolyData>::New();
> clip->SetInput(loop->GetOutput());
> clip->Update();
>
> vtkSmartPointer<vtkMassProperties> mass =
> vtkSmartPointer<vtkMassProperties>::New();
> mass->SetInput(clip->GetOutput());
> std::cout << "Area = " << mass->GetSurfaceArea() << "[mm]";
> }
> else
> std::cout << "Trace not closed";
> }
>
> vtkITWCallback():polyData(0){}
>
> vtkPolyData *polyData;
>
>
> };
>
> int main(int argc, char *argv[])
> {
> bool usePLY = true;
> bool hasTexture = false;
>
> std::string input = " ";
> std::cout << "Use obj (y/n):\n>";
> std::getline(cin,input);
>
> if(input == "y" || input == "Y")
> usePLY = false;
>
> vtkSmartPointer<vtkPolyData> polyData;
> polyData = vtkSmartPointer<vtkPolyData>::New();
>
> vtkSmartPointer<vtkTexture> texture =
> vtkSmartPointer<vtkTexture>::New();
>
> if(usePLY)
> {
> std::cout << "Using *.ply";
> vtkSmartPointer<vtkPLYReader> plyReader =
> vtkSmartPointer<vtkPLYReader>::New();
>
> plyReader->SetFileName("AreaTruth.ply");
> plyReader->Update();
> polyData = plyReader->GetOutput();
>
> }
> else
> {
> std::cout << "Using *.obj";
> vtkSmartPointer<vtkOBJReader> objReader =
> vtkSmartPointer<vtkOBJReader>::New();
>
> objReader->SetFileName("AreaTruth.obj");
> objReader->Update();
> polyData = objReader->GetOutput();
>
> hasTexture = true;
>
> vtkSmartPointer<vtkJPEGReader> jpgReader =
> vtkSmartPointer<vtkJPEGReader>::New();
> jpgReader->SetFileName("AreaTruth_T1.jpg");
> jpgReader->Update();
>
>
> texture->SetInputConnection(jpgReader->GetOutputPort());
> texture->InterpolateOn();
>
>
> }
>
> // Create a mapper and actor
> vtkSmartPointer<vtkPolyDataMapper> mapper =
> vtkSmartPointer<vtkPolyDataMapper>::New();
> mapper->SetInput(polyData);
> vtkSmartPointer<vtkActor> actor =
> vtkSmartPointer<vtkActor>::New();
> actor->SetMapper(mapper);
>
> if(hasTexture)
> actor->SetTexture(texture);
>
> // A renderer and render window
> vtkSmartPointer<vtkRenderer> renderer =
> vtkSmartPointer<vtkRenderer>::New();
> vtkSmartPointer<vtkRenderWindow> renderWindow =
> vtkSmartPointer<vtkRenderWindow>::New();
> renderWindow->AddRenderer(renderer);
> renderer->AddActor(actor);
>
> // An interactor
> vtkSmartPointer<vtkRenderWindowInteractor> renderWindowInteractor =
> vtkSmartPointer<vtkRenderWindowInteractor>::New();
> renderWindowInteractor->SetRenderWindow(renderWindow);
>
> vtkSmartPointer<vtkInteractorStyleTrackballCamera> style =
> vtkSmartPointer<vtkInteractorStyleTrackballCamera>::New();
>
> renderWindowInteractor->SetInteractorStyle(style);
>
> vtkSmartPointer<vtkCallbackCommand> callback =
> vtkSmartPointer<vtkCallbackCommand>::New();
> callback->SetCallback(CallbackFunction);
>
> vtkSmartPointer<vtkITWCallback> itwCallback =
> vtkSmartPointer<vtkITWCallback>::New();
> itwCallback->polyData = polyData;
>
>
>
> vtkSmartPointer<vtkImageTracerWidget> tracerWidget;
> tracerWidget = vtkSmartPointer<vtkImageTracerWidget>::New();
> tracerWidget->SetInteractor(renderWindowInteractor);
> tracerWidget->SetViewProp(actor);
> tracerWidget->AutoCloseOn();
> tracerWidget->AddObserver(vtkCommand::EndInteractionEvent,
> itwCallback);
> tracerWidget->On();
> renderWindow->Render();
>
> renderWindowInteractor->Initialize();
> renderWindow->Render();
>
>
>
>
> // Begin mouse interaction
>
> renderWindowInteractor->Start();
>
> return EXIT_SUCCESS;
> }
>
>
> --
> View this message in context:
> http://vtk.1045678.n5.nabble.com/Weird-vtkClipPolyData-error-when-using-an-obj-tp4408314p4410434.html
> Sent from the VTK - Users mailing list archive at Nabble.com.
> _______________________________________________
> Powered by www.kitware.com <http://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/20110519/71b491f2/attachment.htm>
More information about the vtkusers
mailing list