Reputation: 25038
Given resulting delaunay triangulation for a mesh in a wired representation, I would like to show surface without the diagonals,I just to visualize a neat square. Is there any option to accomplish this, maybe a filter?
something like
delaunay->BoundingTriangulationOff();
delaunay->SetBoundingTriangulation(0);
but that can be applied to all diagonals...
Other idea is maybe to transform all triangules to squares, do you know n algorithm in c++ or c# that does this?
I used example here
#include <vtkVersion.h>
#include <vtkCellArray.h>
#include <vtkPoints.h>
#include <vtkTriangle.h>
#include <vtkPolyData.h>
#include <vtkPointData.h>
#include <vtkLine.h>
#include <vtkCellLocator.h>
#include <vtkSmartPointer.h>
#include <vtkDelaunay2D.h>
#include <vtkPolyDataMapper.h>
#include <vtkActor.h>
#include <vtkRenderer.h>
#include <vtkRenderWindow.h>
#include <vtkRenderWindowInteractor.h>
#include <vtkProperty.h>
#include <vtkVertexGlyphFilter.h>
int main(int, char *[])
{
// Create a set of heighs on a grid.
// This is often called a "terrain map".
vtkSmartPointer<vtkPoints> points =
vtkSmartPointer<vtkPoints>::New();
unsigned int GridSize = 10;
for(unsigned int x = 0; x < GridSize; x++)
{
for(unsigned int y = 0; y < GridSize; y++)
{
points->InsertNextPoint(x, y, (x+y)/(y+1));
}
}
// Add the grid points to a polydata object
vtkSmartPointer<vtkPolyData> polydata =
vtkSmartPointer<vtkPolyData>::New();
polydata->SetPoints(points);
// Triangulate the grid points
vtkSmartPointer<vtkDelaunay2D> delaunay =
vtkSmartPointer<vtkDelaunay2D>::New();
#if VTK_MAJOR_VERSION <= 5
delaunay->SetInput(polydata);
#else
delaunay->SetInputData(polydata);
#endif
delaunay->Update();
// Visualize
vtkSmartPointer<vtkPolyDataMapper> meshMapper =
vtkSmartPointer<vtkPolyDataMapper>::New();
meshMapper->SetInputConnection(delaunay->GetOutputPort());
vtkSmartPointer<vtkActor> meshActor =
vtkSmartPointer<vtkActor>::New();
meshActor->SetMapper(meshMapper);
vtkSmartPointer<vtkVertexGlyphFilter> glyphFilter =
vtkSmartPointer<vtkVertexGlyphFilter>::New();
#if VTK_MAJOR_VERSION <= 5
glyphFilter->SetInputConnection(polydata->GetProducerPort());
#else
glyphFilter->SetInputData(polydata);
#endif
glyphFilter->Update();
vtkSmartPointer<vtkPolyDataMapper> pointMapper =
vtkSmartPointer<vtkPolyDataMapper>::New();
pointMapper->SetInputConnection(glyphFilter->GetOutputPort());
vtkSmartPointer<vtkActor> pointActor =
vtkSmartPointer<vtkActor>::New();
pointActor->GetProperty()->SetColor(1,0,0);
pointActor->GetProperty()->SetPointSize(3);
pointActor->SetMapper(pointMapper);
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(meshActor);
renderer->AddActor(pointActor);
renderer->SetBackground(.3, .6, .3); // Background color green
renderWindow->Render();
renderWindowInteractor->Start();
return EXIT_SUCCESS;
}
Upvotes: 1
Views: 732
Reputation: 2105
I have looked for Triangle Tesselation from points in C# and not found anything. When I am to the point where I will have to use it in a few months, I expect I will have to implement my own. In the mean time, the wikipedia article on Delauney Tesselations is a little dense (hard to understand), but it is the best starting-off point I could find (for hand-rolling your own).
After you perform the tesselation (which I have not helped you with), you should make your model-triangles into Triangle objects which are MeshGeometry3D objects of WPF's Viewport3D. This will do the work of hiding farther triangles covered by nearer ones. Charles Petzold's book '3D Programming For Windows' helped me a lot. But what helped me the most was 'WPF 3D Primer' by Dario Solera http://www.codeproject.com/Articles/23332/WPF-3D-Primer All I did to get a rather nice application was start with Solera's code and modify it one step at a time until I had something very different from his project, but I could not have done it without his project.
Upvotes: 2