Difference between revisions of "VTK/Examples/Cxx/Meshes/BoundaryEdges"

From KitwarePublic
< VTK‎ | Examples‎ | Cxx
Jump to navigationJump to search
Line 4: Line 4:
 
<source lang="cpp">
 
<source lang="cpp">
 
#include <vtkSmartPointer.h>
 
#include <vtkSmartPointer.h>
#include <vtkFeatureEdges.h>
 
 
#include <vtkPolyData.h>
 
#include <vtkPolyData.h>
 
#include <vtkXMLPolyDataReader.h>
 
#include <vtkXMLPolyDataReader.h>
 
#include <vtkXMLPolyDataWriter.h>
 
#include <vtkXMLPolyDataWriter.h>
 +
#include <vtkFeatureEdges.h>
  
 
int main(int argc, char *argv[])
 
int main(int argc, char *argv[])
 
{
 
{
 
   if(argc != 3)
 
   if(argc != 3)
  {
+
    {
 
     vtkstd::cout << "Required arguments: InputFilename OutputFilename" << vtkstd::endl;
 
     vtkstd::cout << "Required arguments: InputFilename OutputFilename" << vtkstd::endl;
 
     exit(-1);
 
     exit(-1);
  }
+
    }
 
    
 
    
   vtkstd::string InputFilename = argv[1];
+
   vtkstd::string inputFilename = argv[1];
   vtkstd::string OutputFilename = argv[2];
+
   vtkstd::string outputFilename = argv[2];
 
    
 
    
   vtkSmartPointer<vtkXMLPolyDataReader> Reader = vtkSmartPointer<vtkXMLPolyDataReader>::New();
+
   vtkSmartPointer<vtkXMLPolyDataReader> reader = vtkSmartPointer<vtkXMLPolyDataReader>::New();
   Reader->SetFileName(InputFilename.c_str());
+
   reader->SetFileName(inputFilename.c_str());
   Reader->Update();
+
   reader->Update();
 
    
 
    
   vtkSmartPointer<vtkFeatureEdges> FeatureEdges = vtkSmartPointer<vtkFeatureEdges>::New();
+
   vtkSmartPointer<vtkFeatureEdges> featureEdges = vtkSmartPointer<vtkFeatureEdges>::New();
   FeatureEdges->SetInput(Reader->GetOutput());
+
   featureEdges->SetInput(reader->GetOutput());
   FeatureEdges->BoundaryEdgesOn();
+
   featureEdges->BoundaryEdgesOn();
   FeatureEdges->FeatureEdgesOff();
+
   featureEdges->FeatureEdgesOff();
   FeatureEdges->ManifoldEdgesOff();
+
   featureEdges->ManifoldEdgesOff();
   FeatureEdges->NonManifoldEdgesOff();
+
   featureEdges->NonManifoldEdgesOff();
 
    
 
    
   vtkSmartPointer<vtkXMLPolyDataWriter> Writer = vtkSmartPointer<vtkXMLPolyDataWriter>::New();
+
   vtkSmartPointer<vtkXMLPolyDataWriter> writer = vtkSmartPointer<vtkXMLPolyDataWriter>::New();
   Writer->SetFileName(OutputFilename.c_str());
+
   writer->SetFileName(outputFilename.c_str());
   Writer->SetInput(FeatureEdges->GetOutput());
+
   writer->SetInput(featureEdges->GetOutput());
   Writer->Write();
+
   writer->Write();
 
    
 
    
 
   return 0;
 
   return 0;

Revision as of 21:18, 12 December 2009

This filter will extract the boundary edges of a mesh. An example file is here. This is a 10x10 grid which forms a plane. The boundary edges are the outside edge of the plane only.

BoundaryEdges.cxx

#include <vtkSmartPointer.h>
#include <vtkPolyData.h>
#include <vtkXMLPolyDataReader.h>
#include <vtkXMLPolyDataWriter.h>
#include <vtkFeatureEdges.h>

int main(int argc, char *argv[])
{
  if(argc != 3)
    {
    vtkstd::cout << "Required arguments: InputFilename OutputFilename" << vtkstd::endl;
    exit(-1);
    }
  
  vtkstd::string inputFilename = argv[1];
  vtkstd::string outputFilename = argv[2];
  
  vtkSmartPointer<vtkXMLPolyDataReader> reader = vtkSmartPointer<vtkXMLPolyDataReader>::New();
  reader->SetFileName(inputFilename.c_str());
  reader->Update();
  
  vtkSmartPointer<vtkFeatureEdges> featureEdges = vtkSmartPointer<vtkFeatureEdges>::New();
  featureEdges->SetInput(reader->GetOutput());
  featureEdges->BoundaryEdgesOn();
  featureEdges->FeatureEdgesOff();
  featureEdges->ManifoldEdgesOff();
  featureEdges->NonManifoldEdgesOff();
  
  vtkSmartPointer<vtkXMLPolyDataWriter> writer = vtkSmartPointer<vtkXMLPolyDataWriter>::New();
  writer->SetFileName(outputFilename.c_str());
  writer->SetInput(featureEdges->GetOutput());
  writer->Write();
  
  return 0;
}

==CMakeLists.txt

cmake_minimum_required(VERSION 2.6)

PROJECT(BoundaryEdges)

FIND_PACKAGE(VTK REQUIRED)
INCLUDE(${VTK_USE_FILE})

ADD_EXECUTABLE(BoundaryEdges BoundaryEdges.cxx)
TARGET_LINK_LIBRARIES(BoundaryEdges vtkHybrid)