[vtkusers] Problems with massProperties at getting area from ContourWidget
Rodrigo Lovera
lobo.theslayer at gmail.com
Mon Dec 3 14:28:30 EST 2012
OK, these 'd be the example:
#include <vtkSmartPointer.h>
#include <vtkProperty.h>
#include <vtkContourWidget.h>
#include <vtkOrientedGlyphContourRepresentation.h>
#include <vtkRenderer.h>
#include <vtkRenderWindow.h>
#include <vtkRenderWindowInteractor.h>
#include <vtkCommand.h>
#include <vtkDebugLeaks.h>
#include <vtkCamera.h>
#include <vtkPlane.h>
#include <vtkPolyData.h>
#include <vtkCellArray.h>
#include <vtkPoints.h>
#include <vtkMath.h>
#include <vtkWidgetEvent.h>
#include <vtkWidgetEventTranslator.h>
#include <vtkTriangleFilter.h>
#include <vtkMassProperties.h>
int main( int argc, char *argv[] )
{
// Create the RenderWindow, Renderer and both Actors
//
vtkSmartPointer<vtkRenderer> renderer =
vtkSmartPointer<vtkRenderer>::New();
vtkSmartPointer<vtkRenderWindow> renderWindow =
vtkSmartPointer<vtkRenderWindow>::New();
renderWindow->AddRenderer(renderer);
vtkSmartPointer<vtkRenderWindowInteractor> interactor =
vtkSmartPointer<vtkRenderWindowInteractor>::New();
interactor->SetRenderWindow(renderWindow);
renderer->SetBackground(0.1, 0.2, 0.4);
renderWindow->SetSize(600, 600);
vtkSmartPointer<vtkOrientedGlyphContourRepresentation> contourRep =
vtkSmartPointer<vtkOrientedGlyphContourRepresentation>::New();
contourRep->GetLinesProperty()->SetColor(1, 0, 0); //set color to red
vtkSmartPointer<vtkContourWidget> contourWidget =
vtkSmartPointer<vtkContourWidget>::New();
contourWidget->SetInteractor(interactor);
contourWidget->SetRepresentation(contourRep);
contourWidget->On();
for (int i = 0; i < argc; i++)
{
if (strcmp("-Shift", argv[i]) == 0)
{
contourWidget->GetEventTranslator()->RemoveTranslation(
vtkCommand::LeftButtonPressEvent );
contourWidget->GetEventTranslator()->SetTranslation(
vtkCommand::LeftButtonPressEvent,
vtkWidgetEvent::Translate );
}
else if (strcmp("-Scale", argv[i]) == 0)
{
contourWidget->GetEventTranslator()->RemoveTranslation(
vtkCommand::LeftButtonPressEvent );
contourWidget->GetEventTranslator()->SetTranslation(
vtkCommand::LeftButtonPressEvent,
vtkWidgetEvent::Scale );
}
}
vtkSmartPointer<vtkPolyData> pd = vtkSmartPointer<vtkPolyData>::New();
vtkSmartPointer<vtkPoints> points = vtkSmartPointer<vtkPoints>::New();
vtkSmartPointer<vtkCellArray> lines =
vtkSmartPointer<vtkCellArray>::New();
vtkIdType* lineIndices = new vtkIdType[21];
for (int i = 0; i< 20; i++)
{
const double angle = 2.0*vtkMath::Pi()*i/20.0;
points->InsertPoint(static_cast<vtkIdType>(i), 0.1*cos(angle),
0.1*sin(angle), 0.0 );
lineIndices[i] = static_cast<vtkIdType>(i);
}
lineIndices[20] = 0;
lines->InsertNextCell(21,lineIndices);
delete [] lineIndices;
pd->SetPoints(points);
pd->SetLines(lines);
contourWidget->Initialize(pd);
contourWidget->Render();
renderer->ResetCamera();
renderWindow->Render();
interactor->Initialize();
interactor->Start();
vtkSmartPointer< vtkTriangleFilter > triangles =
vtkSmartPointer< vtkTriangleFilter >::New();
triangles->SetInput(contourRep->GetContourRepresentationAsPolyData());
vtkSmartPointer< vtkMassProperties > massProp =
vtkSmartPointer< vtkMassProperties >::New();
massProp->SetInput(triangles->GetOutput());
double algo = massProp->GetSurfaceArea();
std::cout<< algo;
contourWidget->Off();
return EXIT_SUCCESS;
}
There's is the contourwidget example but i'm adding the pipe I think 'd be
necessary to compute the area.
It still gives me same error as before at closing the renderwindow for some
reason:
Warning: In C:\Users\RODRIGO LOVERA\Documents\PUCP\Tesis\VTK
5.10\VTK\Graphics\vtkMassProperties.cxx, line 120
vtkMassProperties (04C64588): Input data type must be VTK_TRIANGLE not 3
Hope you can help me get throught these or maybe give some other advice on
how to get the value of the area contained by a contourwidget created at
will.
Regards,
Rodrigo Lovera
2012/12/3 David Doria <daviddoria at gmail.com>
> On Mon, Dec 3, 2012 at 2:00 PM, Rodrigo Lovera <lobo.theslayer at gmail.com>wrote:
>
>> Hello everyone,
>>
>> I've applied the vtkContourWidget in the same way the distancewidget is
>> applied in the QT VTK FOUR PANE VIEW EXAMPLE
>>
>> so far everything is fine, but I'm trying now to compute the area so I
>> connect the following code to an pushButton which 'll be activated after
>> finishing drawing the contour.
>>
>> vtkSmartPointer< vtkTriangleFilter > triangleTrans =
>> vtkSmartPointer< vtkTriangleFilter >::New();
>>
>> triangleTrans->SetInput(contourRepresentation->GetContourRepresentationAsPolyData());
>> vtkSmartPointer< vtkMassProperties > massProp =
>> vtkSmartPointer< vtkMassProperties >::New();
>> massProp->SetInput(triangleTrans->GetOutput());
>> massProp->GetSurfaceArea();
>> this->ui->surfaceAreaLabel->setNum(massProp->GetSurfaceArea());
>>
>> What I'm trying to do is convert the contour in a triangle mesh so then I
>> can apply vtkMassProperties and get the surface area which is my goal.
>>
>> Everythings build ok, but once in the gui when pushing the button... it
>> gives me the following error:
>>
>> Warning: In C:\Users\RODRIGO LOVERA\Documents\PUCP\Tesis\VTK
>> 5.10\VTK\Graphics\vtkMassProperties.cxx, line 120
>> vtkMassProperties (04C64588): Input data type must be VTK_TRIANGLE not 3
>>
>> What I use to draw the contours is the following code:
>>
>
> As usual, I suggest you create a compilable example. It doesn't sound like
> this has anything to do with Qt, so it should be a single, self contained
> file (generate data similar to the data you are reading in your real code).
>
> David
>
--
*Rodrigo aka WarHearT*
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.vtk.org/pipermail/vtkusers/attachments/20121203/76fbba09/attachment.htm>
More information about the vtkusers
mailing list