[vtkusers] question about mesh ?
agatte
agatakrason at gmail.com
Tue Aug 14 08:08:32 EDT 2012
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<<std::endl;
std::cout<<"number_of_triangles: "
<<number_of_triangles<<std::endl;
for (vtkIdType i = 0; i < 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.
More information about the vtkusers
mailing list