[vtkusers] tetrahedron mesh

Longfei Cong lfcong at nlpr.ia.ac.cn
Tue Mar 9 02:39:04 EST 2004


Hivtkusers,
        I have some problem in my using vtkClipVolume to generate mesh . The input data is a ellipsoid in binary image, the intensity of which is set 200. I can use the vtkDataSetMapper to visualize the  ellipsoid. But I want to get what really the mesh are. There are problem when I use the  vtkUnstructuredGridWriter to write the mesh to a file. Could you tell me How can I get the mesh. 

 the code is as below

#include "itkImage.h"
#include "itkImageFileReader.h"
#include "itkImageToVTKImageFilter.h"
#include "vtkImageViewer.h"
#include "vtkRenderWindow.h"
#include "vtkRenderWindowInteractor.h"
#include "vtkClipVolume.h" 
#include "vtkUnstructuredGrid.h" 
#include "vtkImageData.h"
#include "vtkHedgeHog.h"
#include "vtkActor.h"
#include "vtkCamera.h"
#include "vtkPolyDataMapper.h"
#include "vtkProperty.h"
#include "vtkRenderer.h"
#include "vtkQuadric.h"
#include "vtkSampleFunction.h"
#include "vtkImplicitDataSet.h"
#include "vtkImplicitWindowFunction.h"
#include "vtkDataSetMapper.h"
#include "vtkOutlineFilter.h"
#include "vtkUnstructuredGridWriter.h"
int main()
 {
// Example demonstrates how to generate a 3D tetrahedra mesh from a volume. This example
// differs from clipVolume.tcl in that the mesh is generated within a range of contour values.
//

	char dataru[]="smooth.mhd";	
typedef itk::Image<double,3> ImageType;
typedef itk::ImageFileReader<ImageType> ReaderType;
typedef itk::ImageToVTKImageFilter<ImageType> ConnectorType;

ReaderType::Pointer reader= ReaderType::New();
ConnectorType::Pointer connector= ConnectorType::New();
vtkClipVolume *clip =vtkClipVolume::New();
reader->SetFileName( dataru);
connector->SetInput( reader->GetOutput() );
connector->Update();

cout << "\nClipping Volume"; 
clip->SetInput(connector->GetOutput()); 
clip->SetValue(200);
clip->GenerateClippedOutputOff();
vtkUnstructuredGrid *sgrid =clip->GetClippedOutput();
sgrid->DeepCopy( clip->GetClippedOutput());

//###########################
vtkUnstructuredGridWriter *writer=vtkUnstructuredGridWriter::New();
writer->SetFileName("unname.vtk");
writer->SetInput(clip->GetClippedOutput());
cout <<"\n\nrrrrrrrrrrrrrrrrrddddd\n";  
writer->Update();
writer->Delete();
//###########################


  vtkDataSetMapper *clipMapper=vtkDataSetMapper::New();
  clipMapper-> SetInput( clip->GetOutput());
  clipMapper-> ScalarVisibilityOff();

vtkActor *clipActor=vtkActor::New();
  clipActor-> SetMapper( clipMapper);
  clipActor-> GetProperty()-> SetColor( .8, .4, .4);

//# Create outline
vtkOutlineFilter *outline=vtkOutlineFilter::New();;
  outline->SetInput( clip->GetOutput());

vtkPolyDataMapper *outlineMapper=vtkPolyDataMapper::New();
outlineMapper-> SetInput(outline-> GetOutput());

vtkActor *outlineActor=vtkActor::New();
  outlineActor-> SetMapper (outlineMapper);
  outlineActor->GetProperty()-> SetColor (0, 0, 0);
//eval 
//# Define graphics objects
vtkRenderer *ren1=vtkRenderer::New();
vtkRenderWindow *renWin=vtkRenderWindow::New();
    renWin-> AddRenderer( ren1);
	vtkRenderWindowInteractor *iren=vtkRenderWindowInteractor::New();
    iren-> SetRenderWindow (renWin);

ren1-> SetBackground (1, 1, 1);
ren1-> AddActor( clipActor);
ren1 ->AddActor( outlineActor);
renWin->SetSize(300,300);
renWin->Render();
iren->Start();
return 0;
}
 
Best regards

        Longfei Cong
        lfcong at nlpr.ia.ac.cn
          2004-03-09






More information about the vtkusers mailing list