📄 meshcellvisitor2.cxx
字号:
// Creating and associating the Triangles
//
cellpointer.TakeOwnership( new TriangleType );
cellpointer->SetPointId( 0, 0 );
cellpointer->SetPointId( 1, 1 );
cellpointer->SetPointId( 2, 2 );
mesh->SetCell( 1, cellpointer );
cellpointer.TakeOwnership( new TriangleType );
cellpointer->SetPointId( 0, 0 );
cellpointer->SetPointId( 1, 2 );
cellpointer->SetPointId( 2, 3 );
mesh->SetCell( 2, cellpointer );
cellpointer.TakeOwnership( new TriangleType );
cellpointer->SetPointId( 0, 0 );
cellpointer->SetPointId( 1, 3 );
cellpointer->SetPointId( 2, 1 );
mesh->SetCell( 3, cellpointer );
cellpointer.TakeOwnership( new TriangleType );
cellpointer->SetPointId( 0, 3 );
cellpointer->SetPointId( 1, 2 );
cellpointer->SetPointId( 2, 1 );
mesh->SetCell( 4, cellpointer );
// Creating and associating the Edges
//
cellpointer.TakeOwnership( new LineType );
cellpointer->SetPointId( 0, 0 );
cellpointer->SetPointId( 1, 1 );
mesh->SetCell( 5, cellpointer );
cellpointer.TakeOwnership( new LineType );
cellpointer->SetPointId( 0, 1 );
cellpointer->SetPointId( 1, 2 );
mesh->SetCell( 6, cellpointer );
cellpointer.TakeOwnership( new LineType );
cellpointer->SetPointId( 0, 2 );
cellpointer->SetPointId( 1, 0 );
mesh->SetCell( 7, cellpointer );
cellpointer.TakeOwnership( new LineType );
cellpointer->SetPointId( 0, 1 );
cellpointer->SetPointId( 1, 3 );
mesh->SetCell( 8, cellpointer );
cellpointer.TakeOwnership( new LineType );
cellpointer->SetPointId( 0, 3 );
cellpointer->SetPointId( 1, 2 );
mesh->SetCell( 9, cellpointer );
cellpointer.TakeOwnership( new LineType );
cellpointer->SetPointId( 0, 3 );
cellpointer->SetPointId( 1, 0 );
mesh->SetCell( 10, cellpointer );
// Creating and associating the Vertices
//
cellpointer.TakeOwnership( new VertexType );
cellpointer->SetPointId( 0, 0 );
mesh->SetCell( 11, cellpointer );
cellpointer.TakeOwnership( new VertexType );
cellpointer->SetPointId( 0, 1 );
mesh->SetCell( 12, cellpointer );
cellpointer.TakeOwnership( new VertexType );
cellpointer->SetPointId( 0, 2 );
mesh->SetCell( 13, cellpointer );
cellpointer.TakeOwnership( new VertexType );
cellpointer->SetPointId( 0, 3 );
mesh->SetCell( 14, cellpointer );
// Simple verification of the number of points and cells inserted
//
std::cout << "# Points= " << mesh->GetNumberOfPoints() << std::endl;
std::cout << "# Cell = " << mesh->GetNumberOfCells() << std::endl;
// Software Guide : BeginLatex
//
// \index{itk::Mesh!Cell\-Interface\-Visitor\-Implementation}
// \index{itk::Mesh!CellInterfaceVisitor}
// \index{itk::Mesh!CellVisitor}
// \index{CellVisitor}
//
// With the cell visitors we proceed now to instantiate CellVisitor
// implementations. The visitor classes defined above are used as template
// arguments of the cell visitor implementation.
//
// Software Guide : EndLatex
// Software Guide : BeginCodeSnippet
typedef itk::CellInterfaceVisitorImplementation<
PixelType, MeshType::CellTraits, VertexType, CustomVertexVisitor
> VertexVisitorInterfaceType;
typedef itk::CellInterfaceVisitorImplementation<
PixelType, MeshType::CellTraits, LineType, CustomLineVisitor
> LineVisitorInterfaceType;
typedef itk::CellInterfaceVisitorImplementation<
PixelType, MeshType::CellTraits, TriangleType, CustomTriangleVisitor
> TriangleVisitorInterfaceType;
typedef itk::CellInterfaceVisitorImplementation<
PixelType, MeshType::CellTraits, TetrahedronType, CustomTetrahedronVisitor
> TetrahedronVisitorInterfaceType;
// Software Guide : EndCodeSnippet
// Software Guide : BeginLatex
//
// Note that the actual \code{CellInterfaceVisitorImplementation} is
// templated over the PixelType, the CellTraits, the CellType to be visited
// and the Visitor class defining what to do with the cell.
//
// A visitor implementation class can now be created using the normal
// invocation to its \code{New()} method and assigning the result to a
// \doxygen{SmartPointer}.
//
// Software Guide : EndLatex
// Software Guide : BeginCodeSnippet
VertexVisitorInterfaceType::Pointer vertexVisitor =
VertexVisitorInterfaceType::New();
LineVisitorInterfaceType::Pointer lineVisitor =
LineVisitorInterfaceType::New();
TriangleVisitorInterfaceType::Pointer triangleVisitor =
TriangleVisitorInterfaceType::New();
TetrahedronVisitorInterfaceType::Pointer tetrahedronVisitor =
TetrahedronVisitorInterfaceType::New();
// Software Guide : EndCodeSnippet
// Software Guide : BeginLatex
//
// Remember that the LineVisitor required the pointer to the mesh object
// since it needs to get access to actual point coordinates. This is done by
// invoking the \code{SetMesh()} method defined above.
//
// Software Guide : EndLatex
// Software Guide : BeginCodeSnippet
lineVisitor->SetMesh( mesh );
// Software Guide : EndCodeSnippet
// Software Guide : BeginLatex
//
// Looking carefully you will noticed that the \code{SetMesh()} method is
// declared in \code{CustomLineVisitor} but we are invoking it on
// \code{LineVisitorInterfaceType}. This is possible thanks to the way in
// which the VisitorInterfaceImplementation is defined. This class derives
// from the visitor type provided by the user as the fourth template
// parameter. \code{LineVisitorInterfaceType} is then a derived class of
// \code{CustomLineVisitor}.
//
// Software Guide : EndLatex
// Software Guide : BeginLatex
//
// The set of visitors should now be registered with the MultiVisitor class
// that will walk through the cells and delegate action to every registered
// visitor when the appropriate cell type is encountered. The following
// lines create a MultiVisitor object.
//
// \index{CellMultiVisitorType}
// \index{MultiVisitor}
// \index{itk::Mesh!MultiVisitor}
//
// Software Guide : EndLatex
// Software Guide : BeginCodeSnippet
typedef CellType::MultiVisitor CellMultiVisitorType;
CellMultiVisitorType::Pointer multiVisitor = CellMultiVisitorType::New();
// Software Guide : EndCodeSnippet
// Software Guide : BeginLatex
//
// Every visitor implementation is registered with the Mesh using the
// \code{AddVisitor()} method.
//
// \index{itk::Mesh!AddVisitor()}
// \index{AddVisitor()!itk::Mesh}
//
// Software Guide : EndLatex
// Software Guide : BeginCodeSnippet
multiVisitor->AddVisitor( vertexVisitor );
multiVisitor->AddVisitor( lineVisitor );
multiVisitor->AddVisitor( triangleVisitor );
multiVisitor->AddVisitor( tetrahedronVisitor );
// Software Guide : EndCodeSnippet
// Software Guide : BeginLatex
//
// Finally, the iteration over the cells is triggered by calling the method
// \code{Accept()} on the Mesh class.
//
// \index{itk::Mesh!Accept()}
// \index{Accept()!itk::Mesh!}
//
// Software Guide : EndLatex
// Software Guide : BeginCodeSnippet
mesh->Accept( multiVisitor );
// Software Guide : EndCodeSnippet
// Software Guide : BeginLatex
//
// The \code{Accept()} method will iterate over all the cells and for each
// one will invite the MultiVisitor to attempt an action on the cell. If no
// visitor is interested on the current cell type, the cell is just ignored
// and skipped.
//
// Software Guide : EndLatex
return 0;
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -