<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
</head>
<body bgcolor="#FFFFFF">
Bill,<br>
<br>
thank you so much for the prompt and effective reply.<br>
I uniformed the normals in the triangles and now it works.<br>
<br>
I must admit however that the graphical effect of the original version was interesting :-)<br>
<br>
Thanks again<br>
<br>
Michele<br>
<div class="moz-cite-prefix">Il 06/06/2013 18:09, Bill Lorensen ha scritto:<br>
</div>
<blockquote type="cite">
<div dir="ltr">
<div>
<div>Thanks for providing a complete example. It makes it much easrie to help.<br>
<br>
</div>
Your triangles are not ordered consistently. To see this set the backface property to a different color.<br>
<br>
</div>
#include "vtkProperty.h"<br>
<br>
<br>
...<br>
<br>
<br>
vtkSmartPointer<vtkProperty> back =<br>
vtkSmartPointer<vtkProperty>::New();<br>
back->SetColor(1,0,0);<br>
<br>
vtkSmartPointer<vtkActor> actor = vtkSmartPointer<vtkActor>::New();<br>
actor->SetMapper(mapper);<br>
actor->SetBackfaceProperty(back);<br>
<br>
<br>
</div>
<div class="gmail_extra"><br>
<br>
<div class="gmail_quote">On Thu, Jun 6, 2013 at 10:33 AM, Michele <span dir="ltr">
<<a href="mailto:michele.conconi@unibo.it" target="_blank">michele.conconi@unibo.it</a>></span> wrote:<br>
<blockquote class="gmail_quote" style="margin:0 0 0
.8ex; border-left:1px #ccc solid; padding-left:1ex">
Hi everybody,<br>
<br>
I am tring to build a polydata starting from an ordered set of points in<br>
space in order to evaluate its volume.<br>
<br>
I built an exapmple (see below) which generate a correct visual<br>
representation of the polydata, but the computed volume is wrong (6.8 rather<br>
then 48 mm^3).<br>
<br>
I tried aldo the vtkDelaunay2D, with no better results.<br>
<br>
What am I doing wrong?<br>
Thanks in advance for the help<br>
<br>
Michele<br>
<br>
------------------------------<br>
<br>
<br>
#include <vtkVersion.h><br>
#include <vtkSmartPointer.h><br>
#include <vtkCellArray.h><br>
#include <vtkCellData.h><br>
#include <vtkDoubleArray.h><br>
#include <vtkPoints.h><br>
#include <vtkPolyLine.h><br>
#include <vtkPolyData.h><br>
#include <vtkPolyDataMapper.h><br>
#include <vtkActor.h><br>
#include <vtkRenderWindow.h><br>
#include <vtkRenderer.h><br>
#include <vtkRenderWindowInteractor.h><br>
#include <vtkMassProperties.h><br>
#include <vtkTriangle.h><br>
<br>
<br>
<br>
int main( int argc, char *argv[] )<br>
{<br>
// build the points set to be triangulated<br>
int Np = 5;<br>
double **P1, **P2, **P3;<br>
<br>
P1 = new double*[Np];<br>
P2 = new double*[Np];<br>
P3 = new double*[Np];<br>
<br>
for(int i = 0; i < Np; i++)<br>
{<br>
P1[i] = new double[4];<br>
P2[i] = new double[4];<br>
P3[i] = new double[4];<br>
}<br>
<br>
for(int i=0;i<Np;i++)<br>
{<br>
P1[i][0] = 0+i;<br>
P1[i][1] = 1;<br>
P1[i][2] = 0;<br>
<br>
P2[i][0] = 0+i;<br>
P2[i][1] = 3;<br>
P2[i][2] = 2;<br>
<br>
P3[i][0] = 0+i;<br>
P3[i][1] = 5;<br>
P3[i][2] = 4;<br>
}<br>
<br>
<br>
vtkSmartPointer&lt;vtkPoints> points = vtkSmartPointer<vtkPoints>::New();<br>
<br>
for(int i=0;i<Np;i++)<br>
points->InsertNextPoint(P1[i]);<br>
<br>
for(int i=0;i<Np;i++)<br>
points->InsertNextPoint(P2[i]);<br>
<br>
<br>
for(int i=0;i<Np;i++)<br>
points->InsertNextPoint(P3[i]);<br>
<br>
for(int i=0;i<Np;i++)<br>
points->InsertNextPoint(P1[i][0],0,P1[i][2]);<br>
<br>
<br>
for(int i=0;i<Np;i++)<br>
points->InsertNextPoint(P2[i][0],0,P2[i][2]);<br>
<br>
for(int i=0;i<Np;i++)<br>
points->InsertNextPoint(P3[i][0],0,P3[i][2]);<br>
<br>
<br>
//build manually the triangle<br>
<br>
vtkSmartPointer<vtkCellArray> triangles =<br>
vtkSmartPointer<vtkCellArray>::New();<br>
vtkSmartPointer<vtkTriangle> triangle =<br>
vtkSmartPointer<vtkTriangle>::New();<br>
<br>
// ------------------------------------- base<br>
for(int j=3;j<5;j++)<br>
for(int i = (j*Np)+1; i < (j+1)*Np; i++)<br>
{<br>
triangle->Initialize();<br>
triangle->GetPointIds()->SetId(0,i-1);<br>
triangle->GetPointIds()->SetId(1,i);<br>
triangle->GetPointIds()->SetId(2,Np+i-1);<br>
triangles ->InsertNextCell(triangle);<br>
}<br>
<br>
for(int j=4;j<6;j++)<br>
for(int i = j*Np; i < (j+1)*Np-1; i++)<br>
{<br>
triangle->Initialize();<br>
triangle->GetPointIds()->SetId(0,i);<br>
triangle->GetPointIds()->SetId(1,i+1);<br>
triangle->GetPointIds()->SetId(2,i-Np+1);<br>
triangles ->InsertNextCell(triangle);<br>
}<br>
<br>
<br>
// ---------------------------------------- side 1<br>
<br>
for(int i = 1; i < Np; i++)<br>
{<br>
triangle->Initialize();<br>
triangle->GetPointIds()->SetId(0,i-1);<br>
triangle->GetPointIds()->SetId(1,i);<br>
triangle->GetPointIds()->SetId(2,3*Np+i-1);<br>
triangles ->InsertNextCell(triangle);<br>
}<br>
<br>
for(int i = 3*Np; i < 4*Np-1; i++)<br>
{<br>
triangle->Initialize();<br>
triangle->GetPointIds()->SetId(0,i);<br>
triangle->GetPointIds()->SetId(1,i+1);<br>
triangle->GetPointIds()->SetId(2,i-3*Np+1);<br>
triangles ->InsertNextCell(triangle);<br>
}<br>
<br>
// ---------------------------------------- side 2<br>
for(int i = 2*Np+1; i < 3*Np; i++)<br>
{<br>
triangle->Initialize();<br>
triangle->GetPointIds()->SetId(0,i-1);<br>
triangle->GetPointIds()->SetId(1,i);<br>
triangle->GetPointIds()->SetId(2,3*Np+i-1);<br>
triangles ->InsertNextCell(triangle);<br>
}<br>
<br>
for(int i = 5*Np; i < 6*Np-1; i++)<br>
{<br>
triangle->Initialize();<br>
triangle->GetPointIds()->SetId(0,i);<br>
triangle->GetPointIds()->SetId(1,i+1);<br>
triangle->GetPointIds()->SetId(2,i-3*Np+1);<br>
triangles ->InsertNextCell(triangle);<br>
}<br>
<br>
// ---------------------------------------- side 3<br>
<br>
triangle->Initialize();<br>
triangle->GetPointIds()->SetId(0,0);<br>
triangle->GetPointIds()->SetId(1,3*Np);<br>
triangle->GetPointIds()->SetId(2,4*Np);<br>
triangles ->InsertNextCell(triangle);<br>
<br>
triangle->Initialize();<br>
triangle->GetPointIds()->SetId(0,Np);<br>
triangle->GetPointIds()->SetId(1,4*Np);<br>
triangle->GetPointIds()->SetId(2,5*Np);<br>
triangles ->InsertNextCell(triangle);<br>
<br>
triangle->Initialize();<br>
triangle->GetPointIds()->SetId(0,4*Np);<br>
triangle->GetPointIds()->SetId(1,Np);<br>
triangle->GetPointIds()->SetId(2,0);<br>
triangles ->InsertNextCell(triangle);<br>
<br>
triangle->Initialize();<br>
triangle->GetPointIds()->SetId(0,5*Np);<br>
triangle->GetPointIds()->SetId(1,2*Np);<br>
triangle->GetPointIds()->SetId(2,Np);<br>
triangles ->InsertNextCell(triangle);<br>
<br>
// ---------------------------------------- side 4<br>
<br>
triangle->Initialize();<br>
triangle->GetPointIds()->SetId(0,Np-1);<br>
triangle->GetPointIds()->SetId(1,4*Np-1);<br>
triangle->GetPointIds()->SetId(2,5*Np-1);<br>
triangles ->InsertNextCell(triangle);<br>
<br>
triangle->Initialize();<br>
triangle->GetPointIds()->SetId(0,2*Np-1);<br>
triangle->GetPointIds()->SetId(1,5*Np-1);<br>
triangle->GetPointIds()->SetId(2,6*Np-1);<br>
triangles ->InsertNextCell(triangle);<br>
<br>
triangle->Initialize();<br>
triangle->GetPointIds()->SetId(0,5*Np-1);<br>
triangle->GetPointIds()->SetId(1,2*Np-1);<br>
triangle->GetPointIds()->SetId(2,Np-1);<br>
triangles ->InsertNextCell(triangle);<br>
<br>
triangle->Initialize();<br>
triangle->GetPointIds()->SetId(0,6*Np-1);<br>
triangle->GetPointIds()->SetId(1,3*Np-1);<br>
triangle->GetPointIds()->SetId(2,2*Np-1);<br>
triangles ->InsertNextCell(triangle);<br>
<br>
<br>
// -------------------- top<br>
<br>
for(int j=0;j<2;j++)<br>
for(int i = (j*Np)+1; i < (j+1)*Np; i++)<br>
{<br>
triangle->Initialize();<br>
triangle->GetPointIds()->SetId(0,i-1);<br>
triangle->GetPointIds()->SetId(1,i);<br>
triangle->GetPointIds()->SetId(2,Np+i-1);<br>
triangles ->InsertNextCell(triangle);<br>
}<br>
<br>
for(int j=1;j<3;j++)<br>
for(int i = j*Np; i < (j+1)*Np-1; i++)<br>
{<br>
triangle->Initialize();<br>
triangle->GetPointIds()->SetId(0,i);<br>
triangle->GetPointIds()->SetId(1,i+1);<br>
triangle->GetPointIds()->SetId(2,i-Np+1);<br>
triangles ->InsertNextCell(triangle);<br>
}<br>
<br>
<br>
// build the polydata<br>
<br>
vtkPolyData *polyData = vtkPolyData::New();<br>
<br>
polyData->SetPoints(points);<br>
polyData->SetPolys(triangles );<br>
<br>
<br>
//evaluate the volume : expected outcome for the current points set 48<br>
<br>
vtkMassProperties *mass = vtkMassProperties::New();<br>
<br>
mass->SetInput(polyData);<br>
cout<<"volume "<<mass->GetVolume()<<endl;<br>
<br>
// Setup actor and mapper<br>
vtkSmartPointer&lt;vtkPolyDataMapper> mapper =<br>
vtkSmartPointer<vtkPolyDataMapper>::New();<br>
mapper->SetInput(polyData);<br>
<br>
<br>
vtkSmartPointer<vtkActor> actor = vtkSmartPointer<vtkActor>::New();<br>
actor->SetMapper(mapper);<br>
<br>
// Setup render window, renderer, and interactor<br>
vtkSmartPointer<vtkRenderer> renderer =<br>
vtkSmartPointer<vtkRenderer>::New();<br>
vtkSmartPointer<vtkRenderWindow> renderWindow =<br>
vtkSmartPointer<vtkRenderWindow>::New();<br>
renderWindow->AddRenderer(renderer);<br>
vtkSmartPointer<vtkRenderWindowInteractor> renderWindowInteractor =<br>
vtkSmartPointer<vtkRenderWindowInteractor>::New();<br>
renderWindowInteractor->SetRenderWindow(renderWindow);<br>
renderer->AddActor(actor);<br>
<br>
renderWindow->Render();<br>
renderWindowInteractor->Start();<br>
<br>
return 0;<br>
}<br>
<br>
<br>
<br>
--<br>
View this message in context: <a href="http://vtk.1045678.n5.nabble.com/computing-the-volume-of-a-simple-multi-triangles-polydata-tp5721243.html" target="_blank">
http://vtk.1045678.n5.nabble.com/computing-the-volume-of-a-simple-multi-triangles-polydata-tp5721243.html</a><br>
Sent from the VTK - Users mailing list archive at Nabble.com.<br>
_______________________________________________<br>
Powered by <a href="http://www.kitware.com" target="_blank">www.kitware.com</a><br>
<br>
Visit other Kitware open-source projects at <a href="http://www.kitware.com/opensource/opensource.html" target="_blank">
http://www.kitware.com/opensource/opensource.html</a><br>
<br>
Please keep messages on-topic and check the VTK FAQ at: <a href="http://www.vtk.org/Wiki/VTK_FAQ" target="_blank">
http://www.vtk.org/Wiki/VTK_FAQ</a><br>
<br>
Follow this link to subscribe/unsubscribe:<br>
<a href="http://www.vtk.org/mailman/listinfo/vtkusers" target="_blank">http://www.vtk.org/mailman/listinfo/vtkusers</a><br>
</blockquote>
</div>
<br>
<br clear="all">
<br>
-- <br>
Unpaid intern in BillsBasement at noware dot com<br>
</div>
</blockquote>
<br>
<div class="moz-signature">-- <br>
<b>Eng. Michele Conconi, Ph.D.</b> <br>
Health Sciences and Technologies - Interdepartmental Center for Industrial Research (HST - ICIR)
<br>
Alma Mater Studiorum - University of Bologna <br>
Viale Risorgimento 2, 40136, Bologna, Italy <br>
Email: <a class="moz-txt-link-abbreviated" href="mailto:michele.conconi@unibo.it">
michele.conconi@unibo.it</a> <br>
Website: <a class="moz-txt-link-freetext" href="http://grab.diem.unibo.it/">http://grab.diem.unibo.it/</a>
<br>
Office: (+39) 051 20 93451 <br>
Mobile: (+39) 329 0287996 <br>
<br>
<br>
<br>
<b>INFORMAZIONE RISERVATA E CONFIDENZIALE </b><br>
Questo messaggio contiene informazioni riservate e confidenziali. <br>
Se il lettore non fosse il destinatario del messaggio, inoltrato e ricevuto per errore,
<br>
il testo dovrà essere immediatamente cancellato dal computer del ricevente. <br>
E' assolutamente proibita qualunque circolazione, disseminazione o <br>
copia del messaggio spedito e/o ricevuto per errore. <br>
<br>
<b>CONFIDENTIALITY and WARNING NOTICE </b><br>
This message may contain legally privileged or confidential information. <br>
If the reader is not the intended recipient, you received this message in error <br>
and it should therefore be deleted from your computer at once. <br>
Any dissemination, distribution and copying of a message <br>
mistakenly sent or received is strictly forbidden.</div>
<p><br>
5x1000 AI GIOVANI RICERCATORI<br>
DELL'UNIVERSITÀ DI BOLOGNA <br>
Codice Fiscale: 80007010376 <br>
www.unibo.it/Vademecum5permille<br>
</p>
<p>Questa informativa è inserita in automatico dal sistema al fine esclusivo della realizzazione dei fini istituzionali dell’ente.
</p>
</body>
</html>