[vtkusers] how to build triangle net from contourlines?
6dgis at 163.com
6dgis at 163.com
Sat Jul 30 14:14:56 EDT 2005
Hi, all
I am using vtkMarchingCube to build triangle net from many contourlines, but the result is wrong.:(
I defined an array reprenting the contour data. The element of array is '2' means the point of contourline.
The program is as following:
#include "vtkRenderer.h"
#include "vtkRenderWindow.h"
#include "vtkRenderWindowInteractor.h"
#include "vtkVolume16Reader.h"
#include "vtkPolyDataMapper.h"
#include "vtkActor.h"
#include "vtkOutlineFilter.h"
#include "vtkCamera.h"
#include "vtkProperty.h"
#include "vtkPolyDataNormals.h"
#include "vtkContourFilter.h"
#include "vtkDataSetWriter.h"
#include "vtkImageData.h"
#include "vtkIntArray.h"
#include "vtkPointData.h"
#include "vtkMarchingCubes.h"
int data[] =
{
0,0,0,0,0,0,
0,0,2,2,0,0,
0,2,0,0,2,0,
0,2,0,0,2,0,
0,0,2,2,0,0,
0,0,0,0,0,0, //first slice
0,2,2,2,2,0,
2,0,0,0,0,2,
2,0,0,0,0,2,
2,0,0,0,0,2,
2,0,0,0,0,2,
0,2,2,2,2,0, //second slice
0,2,2,2,2,0,
2,0,0,0,0,2,
2,0,0,0,0,2,
2,0,0,0,0,2,
2,0,0,0,0,2,
0,2,2,2,2,0, //third slice
0,0,0,0,0,0,
0,0,2,2,0,0,
0,2,0,0,2,0,
0,2,0,0,2,0,
0,0,2,2,0,0,
0,0,0,0,0,0, //forth slice
};
int main (int argc, char **argv)
{
vtkRenderer *aRenderer = vtkRenderer::New();
vtkRenderWindow *renWin = vtkRenderWindow::New();
renWin->AddRenderer(aRenderer);
vtkRenderWindowInteractor *iren = vtkRenderWindowInteractor::New();
iren->SetRenderWindow(renWin);
vtkIntArray * array = vtkIntArray::New();
array->SetVoidArray( data, 6*6*4, 1);
vtkImageData * img = vtkImageData::New();
img->SetScalarTypeToInt();
img->GetPointData()->SetScalars(array);
img->SetDimensions(6, 6, 2);
img->SetSpacing(5.0,5.0,5.0);
img->SetOrigin(0,0,0);
vtkMarchingCubes *skinExtractor = vtkMarchingCubes::New();
skinExtractor->SetInput(img);
skinExtractor->SetValue(0, 2);
vtkDataSetWriter *aWriter2 = vtkDataSetWriter::New();
aWriter2->SetFileName("hjf2.vtk");
aWriter2->SetInput((vtkDataSet *)skinExtractor->GetOutput());
aWriter2->Update();
vtkPolyDataMapper *skinMapper = vtkPolyDataMapper::New();
skinMapper->SetInput(skinExtractor->GetOutput());
skinMapper->ScalarVisibilityOff();
vtkActor *skin = vtkActor::New();
skin->SetMapper(skinMapper);
vtkOutlineFilter *outlineData = vtkOutlineFilter::New();
outlineData->SetInput((vtkDataSet*)img);
vtkPolyDataMapper *mapOutline = vtkPolyDataMapper::New();
mapOutline->SetInput(outlineData->GetOutput());
vtkActor *outline = vtkActor::New();
outline->SetMapper(mapOutline);
outline->GetProperty()->SetColor(0,0,0);
vtkCamera *aCamera = vtkCamera::New();
aCamera->SetViewUp (0, 0, -1);
aCamera->SetPosition (0, 1, 0);
aCamera->SetFocalPoint (0, 0, 0);
aCamera->ComputeViewPlaneNormal();
aRenderer->AddActor(outline);
aRenderer->AddActor(skin);
aRenderer->SetActiveCamera(aCamera);
aRenderer->ResetCamera ();
aCamera->Dolly(1.5);
aRenderer->SetBackground(1,1,1);
renWin->SetSize(640, 480);
aRenderer->ResetCameraClippingRange ();
iren->Initialize();
iren->Start();
return 0;
}
But the file "hjf2.vtk" showed that there are only 24 triangles, which only build the triangle net between the second slice and the third slice, why? Any Help? Thx in advance!
6dgis
6dgis at 163.com
2005-07-31
More information about the vtkusers
mailing list