[vtkusers] question about mesh ?

Bill Lorensen bill.lorensen at gmail.com
Tue Aug 14 11:16:48 EDT 2012


Sorry, I cannot read the links to your files.

On Tue, Aug 14, 2012 at 8:08 AM, agatte <agatakrason at gmail.com> wrote:

> Hi ;)
> I have a question about a mesh.
> I read mesh data from txt file ( I attach this file.)
> But I can't receive good structure of mesh (polydata).
> I receive  something like this : (I attach a photo screen )
> When I use vtkVertexGlyphFilter. I receive a point cloud with good shape of
> heart.
> But I need display mesh with triangles/triangleStrips.
> Could You look at this code and this file ?
> I would appreciate for any help please.
> I don't see an error. What is wrong with this code ?
>
> My code is here :
> #include <vtkVersion.h>
> #include <vtkSmartPointer.h>
> #include <vtkPolyDataMapper.h>
> #include <vtkActor.h>
> #include <vtkParticleReader.h>
> #include <vtkRenderWindow.h>
> #include <vtkRenderWindowInteractor.h>
> #include <vtkRenderer.h>
> #include <vtkVertexGlyphFilter.h>
> #include <sstream>
> #include "vtkPolyData.h"
> #include "vtkPoints.h"
> #include "vtkCellArray.h"
> #include <iostream>
> #include <fstream>
> #include <vtkTriangle.h>
> #include <vtkTriangleFilter.h>
> #include <vtkContourFilter.h>
> #include <vtkDelaunay3D.h>
> #include <vtkXMLPolyDataWriter.h>
> #include <vtkXMLUnstructuredGridWriter.h>
> #include <vtkXMLPolyDataWriter.h>
> #include <vtkDataSetSurfaceFilter.h>
> #include <vtkPolyDataWriter.h>
> #include <vtkExtractEdges.h>
> #include <vtkTriangleStrip.h>
> #include <vtkLine.h>
> #include <vtkXMLPolyDataReader.h>
> #include <vtkGeometryFilter.h>
> #include <vtkSurfaceReconstructionFilter.h>
> #include <vtkDelaunay2D.h>
> #include <vtkExtractEdges.h>
> #include <vtkFloatArray.h>
> #include <vtkLookupTable.h>
> #include <vtkStripper.h>
> #include <iostream>
> #include <vector>
> #include <string>
> #include <fstream>
> #include "vtkProperty.h"
>
> using namespace std;
>
>
> int main(int argc, char* argv[])
> {
>
>     const char* filename = "heartmesh.txt";
>         std::ifstream infile(filename);
>     vtkIdType number_of_points, number_of_triangles;
>     infile >> number_of_points >> number_of_triangles;
>     vtkPoints* points = vtkPoints::New();
>     points->SetNumberOfPoints(number_of_points);
>
>         std::cout<<"number_of_points: "<<number_of_points&lt;&lt;std::endl;
>         std::cout&lt;&lt;&quot;number_of_triangles: &quot;
> &lt;&lt;number_of_triangles&lt;&lt;std::endl;
>
>     for (vtkIdType i = 0; i &lt; number_of_points; i++)
>      {
>         double x, y, z;
>         infile >> x >> y >> z;
>         points->SetPoint(i, x, y, z);
>
>      }
>
>     vtkCellArray* polys = vtkCellArray::New();
>
>    for (vtkIdType i = 0; i < number_of_triangles; i++)
>     {
>       vtkIdType a, b, c;
>       infile >> a >> b >> c;
>       polys->InsertNextCell(3);
>       polys->InsertCellPoint(a);
>       polys->InsertCellPoint(b);
>       polys->InsertCellPoint(c);
>
>     }
>
>   vtkPolyData* polydata = vtkPolyData::New();
>   polydata->SetPoints(points);
>   polydata->SetPolys(polys);
>   polydata->Update();
>
>   vtkVertexGlyphFilter* glyphFilter = vtkVertexGlyphFilter::New();
>   glyphFilter->SetInputConnection(polydata->GetProducerPort());
>   glyphFilter->Update();
>
>   vtkDelaunay2D* delaunay = vtkDelaunay2D::New();
>   delaunay->SetInputConnection(glyphFilter->GetOutputPort());
>   delaunay->Update();
>
>   vtkDataSetSurfaceFilter* surfaceFilter = vtkDataSetSurfaceFilter::New();
>   surfaceFilter->SetInputConnection(delaunay->GetOutputPort());
>   surfaceFilter->Update();
>
>   vtkTriangleFilter* triangleFilter = vtkTriangleFilter::New();
>   triangleFilter->SetInputConnection(surfaceFilter->GetOutputPort());
>   triangleFilter->Update();
>
>   // Visualization
>   vtkSmartPointer<vtkPolyDataMapper> mapper =
> vtkSmartPointer<vtkPolyDataMapper>::New();
>  // mapper->SetInput(polydata);
>   mapper->SetInputConnection(triangleFilter->GetOutputPort());
>   vtkSmartPointer<vtkActor> actor = vtkSmartPointer<vtkActor>::New();
>   actor->SetMapper(mapper);
>
>
>
>   //Create a renderer, render window, and interactor
>   vtkSmartPointer<vtkRenderer> renderer =
> vtkSmartPointer<vtkRenderer>::New();
>   vtkSmartPointer<vtkRenderWindow> renderWindow =
> vtkSmartPointer<vtkRenderWindow>::New();
>   renderWindow->AddRenderer(renderer);
>   vtkSmartPointer<vtkRenderWindowInteractor> renderWindowInteractor =
> vtkSmartPointer<vtkRenderWindowInteractor>::New();
>   renderWindowInteractor->SetRenderWindow(renderWindow);
>
>   renderer->AddActor(actor);
>   renderer->SetBackground(0, 0, 0);
>   renderWindow->Render();
>   renderWindowInteractor->Start();
>
>   polydata->Delete();
>   polys->Delete();
>   points->Delete();
>   glyphFilter->Delete();
>   delaunay->Delete();
>   triangleFilter->Delete();
>   surfaceFilter->Delete();
>
>
>
>
>   return EXIT_SUCCESS;
> }
>
>
>
> agatte
>
> http://vtk.1045678.n5.nabble.com/file/n5715236/heartmesh.txt heartmesh.txt
>
>
>
> http://vtk.1045678.n5.nabble.com/file/n5715236/Heart_as_Polydata.png
> http://vtk.1045678.n5.nabble.com/file/n5715236/Heart_as_PointCloud.png
>
>
>
>
> --
> View this message in context:
> http://vtk.1045678.n5.nabble.com/question-about-mesh-tp5715236.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
>



-- 
Unpaid intern in BillsBasement at noware dot com
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.vtk.org/pipermail/vtkusers/attachments/20120814/95370ed6/attachment.htm>


More information about the vtkusers mailing list