📄 三角化.cpp
字号:
spline2TextActor ->GetPositionCoordinate() ->SetValue (24 ,1.5 ,0);
//# ------------------------------------------------------------
//# Create a spiral conic
//# ------------------------------------------------------------
vtkParametricConicSpiral *sconic=vtkParametricConicSpiral::New();
sconic-> SetA (0.8);
sconic-> SetB (2.5);
sconic-> SetC (0.4);
vtkParametricFunctionSource *sconicSource=vtkParametricFunctionSource::New();
sconicSource-> SetParametricFunction (sconic);
sconicSource-> SetScalarModeToDistance();
vtkPolyDataMapper *sconicMapper=vtkPolyDataMapper::New();
sconicMapper-> SetInputConnection (sconicSource ->GetOutputPort());
vtkActor *sconicActor=vtkActor::New();
sconicActor-> SetMapper (sconicMapper);
sconicMapper-> SetScalarRange (0, 9);
sconicActor-> SetPosition (0 ,-4, 0);
sconicActor-> SetScale (1.2 ,1.2, 1.2);
vtkTextMapper *sconicTextMapper=vtkTextMapper::New();
sconicTextMapper-> SetInput ("Spiral Conic");
sconicTextMapper-> GetTextProperty()-> SetJustificationToCentered();
sconicTextMapper-> GetTextProperty()-> SetVerticalJustificationToCentered();
sconicTextMapper ->GetTextProperty()-> SetColor (1 ,0 ,0);
sconicTextMapper-> GetTextProperty()-> SetFontSize (14);
vtkActor2D *sconicTextActor=vtkActor2D::New();
sconicTextActor ->SetMapper (sconicTextMapper);
sconicTextActor ->GetPositionCoordinate() ->SetCoordinateSystemToWorld();
sconicTextActor ->GetPositionCoordinate() ->SetValue (0 ,-6.5 ,0);
//# ------------------------------------------------------------
//# Create Boy's surface
//# ------------------------------------------------------------
vtkParametricBoy *boy=vtkParametricBoy::New();
vtkParametricFunctionSource *boySource=vtkParametricFunctionSource::New();
boySource ->SetParametricFunction (boy);
boySource ->SetScalarModeToModulus();
vtkPolyDataMapper *boyMapper=vtkPolyDataMapper::New();
boyMapper ->SetInputConnection( boySource ->GetOutputPort());
boyMapper ->SetScalarRange( 0, 2);
vtkActor *boyActor=vtkActor::New();
boyActor ->SetMapper (boyMapper);
boyActor ->SetPosition( 8 ,-4 ,0);
boyActor ->SetScale (1.5 ,1.5, 1.5);
vtkTextMapper *boyTextMapper=vtkTextMapper::New();
boyTextMapper ->SetInput ("Boy");
boyTextMapper ->GetTextProperty() ->SetJustificationToCentered();
boyTextMapper ->GetTextProperty()-> SetVerticalJustificationToCentered();
boyTextMapper ->GetTextProperty()-> SetColor (1 ,0 ,0);
boyTextMapper ->GetTextProperty()-> SetFontSize (14);
vtkActor2D *boyTextActor=vtkActor2D::New();
boyTextActor-> SetMapper (boyTextMapper);
boyTextActor-> GetPositionCoordinate()-> SetCoordinateSystemToWorld();
boyTextActor-> GetPositionCoordinate()-> SetValue (8 ,-6.5 ,0);
//# ------------------------------------------------------------
//# Create a cross cap
//# ------------------------------------------------------------
vtkParametricCrossCap *crossCap=vtkParametricCrossCap::New();
vtkParametricFunctionSource *crossCapSource=vtkParametricFunctionSource::New();
crossCapSource ->SetParametricFunction (crossCap);
crossCapSource ->SetScalarModeToY();
vtkPolyDataMapper *crossCapMapper=vtkPolyDataMapper::New();
crossCapMapper ->SetInputConnection (crossCapSource ->GetOutputPort());
vtkActor *crossCapActor=vtkActor::New();
crossCapActor ->SetMapper (crossCapMapper);
crossCapActor ->RotateX (65);
crossCapActor ->SetPosition (16, -4 ,0);
crossCapActor ->SetScale (1.5 ,1.5 ,1.5);
vtkTextMapper *crossCapTextMapper=vtkTextMapper::New();
crossCapTextMapper ->SetInput ("Cross Cap");
crossCapTextMapper-> GetTextProperty() ->SetJustificationToCentered();
crossCapTextMapper-> GetTextProperty() ->SetVerticalJustificationToCentered();
crossCapTextMapper-> GetTextProperty() ->SetColor (1 ,0 ,0);
crossCapTextMapper-> GetTextProperty() ->SetFontSize (14);
vtkActor2D *crossCapTextActor=vtkActor2D::New();
crossCapTextActor ->SetMapper( crossCapTextMapper);
crossCapTextActor ->GetPositionCoordinate() ->SetCoordinateSystemToWorld();
crossCapTextActor ->GetPositionCoordinate() ->SetValue (16, -6.5, 0);
//# ------------------------------------------------------------
//# Create Dini's surface
//# ------------------------------------------------------------
vtkParametricDini *dini=vtkParametricDini::New();
vtkParametricFunctionSource *diniSource=vtkParametricFunctionSource::New();
diniSource ->SetScalarModeToDistance();
diniSource ->SetParametricFunction (dini);
vtkPolyDataMapper *diniMapper=vtkPolyDataMapper::New();
diniMapper ->SetInputConnection (diniSource ->GetOutputPort());
vtkActor *diniActor=vtkActor::New();
diniActor ->SetMapper (diniMapper);
diniActor ->RotateX (-90);
diniActor ->SetPosition (24 ,-3 ,0);
diniActor ->SetScale (1.5 ,1.5 ,0.5);
vtkTextMapper *diniTextMapper=vtkTextMapper::New();
diniTextMapper ->SetInput ("Dini");
diniTextMapper ->GetTextProperty() ->SetJustificationToCentered();
diniTextMapper ->GetTextProperty() ->SetVerticalJustificationToCentered();
diniTextMapper-> GetTextProperty() ->SetColor (1 ,0, 0);
diniTextMapper-> GetTextProperty() ->SetFontSize (14);
vtkActor2D *diniTextActor=vtkActor2D::New();
diniTextActor ->SetMapper (diniTextMapper);
diniTextActor ->GetPositionCoordinate() ->SetCoordinateSystemToWorld();
diniTextActor ->GetPositionCoordinate() ->SetValue (24 ,-6.5 ,0);
//# ------------------------------------------------------------
//# Create Enneper's surface
//# ------------------------------------------------------------
vtkParametricEnneper *enneper=vtkParametricEnneper::New();
vtkParametricFunctionSource *enneperSource=vtkParametricFunctionSource::New();
enneperSource ->SetParametricFunction (enneper);
enneperSource ->SetScalarModeToQuadrant();
vtkPolyDataMapper *enneperMapper=vtkPolyDataMapper::New();
enneperMapper ->SetInputConnection (enneperSource ->GetOutputPort());
enneperMapper ->SetScalarRange (1 ,4);
vtkActor *enneperActor=vtkActor::New();
enneperActor ->SetMapper (enneperMapper);
enneperActor ->SetPosition( 0 ,-12 ,0);
enneperActor ->SetScale (0.25 ,0.25 ,0.25);
vtkTextMapper *enneperTextMapper=vtkTextMapper::New();
enneperTextMapper ->SetInput ("Enneper");
enneperTextMapper ->GetTextProperty() ->SetJustificationToCentered();
enneperTextMapper ->GetTextProperty() ->SetVerticalJustificationToCentered();
enneperTextMapper ->GetTextProperty() ->SetColor (1 ,0 ,0);
enneperTextMapper ->GetTextProperty() ->SetFontSize (14);
vtkActor2D *enneperTextActor =vtkActor2D::New();
enneperTextActor-> SetMapper (enneperTextMapper );
enneperTextActor ->GetPositionCoordinate() ->SetCoordinateSystemToWorld();
enneperTextActor ->GetPositionCoordinate() ->SetValue (0 ,-14.5 ,0);
//# ------------------------------------------------------------
//# Create an ellipsoidal surface
//# ------------------------------------------------------------
vtkParametricEllipsoid *ellipsoid=vtkParametricEllipsoid::New();
ellipsoid ->SetXRadius (1);
ellipsoid ->SetYRadius (0.75);
ellipsoid ->SetZRadius (0.5);
vtkParametricFunctionSource *ellipsoidSource=vtkParametricFunctionSource::New();
ellipsoidSource ->SetParametricFunction (ellipsoid);
ellipsoidSource ->SetScalarModeToZ();
vtkPolyDataMapper *ellipsoidMapper=vtkPolyDataMapper::New();
ellipsoidMapper ->SetInputConnection (ellipsoidSource ->GetOutputPort());
ellipsoidMapper ->SetScalarRange (-0.5, 0.5);
vtkActor *ellipsoidActor=vtkActor::New();
ellipsoidActor ->SetMapper (ellipsoidMapper);
ellipsoidActor ->SetPosition (8 ,-12, 0);
ellipsoidActor ->SetScale (1.5 ,1.5 ,1.5);
vtkTextMapper *ellipsoidTextMapper=vtkTextMapper::New();
ellipsoidTextMapper ->SetInput ("Ellipsoid");
ellipsoidTextMapper ->GetTextProperty() ->SetJustificationToCentered();
ellipsoidTextMapper ->GetTextProperty() ->SetVerticalJustificationToCentered();
ellipsoidTextMapper ->GetTextProperty() ->SetColor (1 ,0 ,0);
ellipsoidTextMapper ->GetTextProperty() ->SetFontSize (14);
vtkActor2D *ellipsoidTextActor =vtkActor2D::New();
ellipsoidTextActor ->SetMapper( ellipsoidTextMapper );
ellipsoidTextActor ->GetPositionCoordinate() ->SetCoordinateSystemToWorld();
ellipsoidTextActor ->GetPositionCoordinate() ->SetValue (8 ,-14.5 ,0);
/*
# ------------------------------------------------------------
# Create an surface with random hills on it.
# Note that for testing, we will disable the
# random generation of the surfaces. This is
# because random number generators do not
# return the same result on different operating
# systems.
# ------------------------------------------------------------*/
vtkParametricRandomHills *randomHills=vtkParametricRandomHills::New();
randomHills ->AllowRandomGenerationOff();
randomHills ->GenerateTheHills();
vtkParametricFunctionSource *randomHillsSource=vtkParametricFunctionSource::New();
randomHillsSource-> SetParametricFunction (randomHills);
randomHillsSource-> GenerateTextureCoordinatesOn();
vtkPolyDataMapper *randomHillsMapper=vtkPolyDataMapper::New();
randomHillsMapper-> SetInputConnection (randomHillsSource->GetOutputPort());
vtkActor *randomHillsActor=vtkActor::New();
randomHillsActor ->SetMapper (randomHillsMapper);
randomHillsActor ->SetPosition (16, -14 ,0);
randomHillsActor ->SetScale (0.2 ,0.2 ,0.2);
randomHillsActor ->SetTexture (texture);
vtkTextMapper *randomHillsTextMapper=vtkTextMapper::New();
randomHillsTextMapper ->SetInput ("Random Hills");
randomHillsTextMapper-> GetTextProperty()-> SetJustificationToCentered();
randomHillsTextMapper-> GetTextProperty() ->SetVerticalJustificationToCentered();
randomHillsTextMapper-> GetTextProperty() ->SetColor (1, 0 ,0);
randomHillsTextMapper-> GetTextProperty() ->SetFontSize (14);
vtkActor2D *randomHillsTextActor =vtkActor2D::New();
randomHillsTextActor ->SetMapper (randomHillsTextMapper );
randomHillsTextActor-> GetPositionCoordinate()-> SetCoordinateSystemToWorld();
randomHillsTextActor-> GetPositionCoordinate() ->SetValue (16 ,-14.5, 0);
//# ------------------------------------------------------------
//# Create an Steiner's Roman Surface.
//# ------------------------------------------------------------
vtkParametricRoman *roman=vtkParametricRoman::New();
roman ->SetRadius (1.5);
vtkParametricFunctionSource *romanSource=vtkParametricFunctionSource::New();
romanSource ->SetParametricFunction( roman);
romanSource ->SetScalarModeToX();
vtkPolyDataMapper *romanMapper=vtkPolyDataMapper::New();
romanMapper ->SetInputConnection( romanSource ->GetOutputPort());
vtkActor *romanActor=vtkActor::New();
romanActor-> SetMapper (romanMapper);
romanActor-> SetPosition (24 ,-12, 0);
vtkTextMapper *romanTextMapper=vtkTextMapper::New();
romanTextMapper-> SetInput( "Roman");
romanTextMapper-> GetTextProperty()-> SetJustificationToCentered();
romanTextMapper-> GetTextProperty()-> SetVerticalJustificationToCentered();
romanTextMapper-> GetTextProperty()-> SetColor (1 ,0 ,0);
romanTextMapper-> GetTextProperty()-> SetFontSize (14);
vtkActor2D *romanTextActor=vtkActor2D::New();
romanTextActor-> SetMapper (romanTextMapper );
romanTextActor-> GetPositionCoordinate()-> SetCoordinateSystemToWorld();
romanTextActor-> GetPositionCoordinate()-> SetValue( 24 ,-14.5, 0);
//# ------------------------------------------------------------
//# Create the RenderWindow, Renderer and both Actors
//# ------------------------------------------------------------
// add actors
ren1->AddViewProp (torusActor);
ren1->AddViewProp (kleinActor);
ren1->AddViewProp (klein2Actor);
ren1->AddViewProp (toroidActor);
ren1->AddViewProp (superEllipsoidActor);
ren1->AddViewProp (mobiusActor);
ren1->AddViewProp (splineActor);
ren1->AddViewProp (spline2Actor);
ren1->AddViewProp (sconicActor);
ren1->AddViewProp (boyActor);
ren1->AddViewProp (crossCapActor);
ren1->AddViewProp (diniActor);
ren1->AddViewProp (enneperActor);
ren1->AddViewProp (ellipsoidActor);
ren1->AddViewProp (randomHillsActor);
ren1->AddViewProp (romanActor);
//add text actors
ren1->AddViewProp (torusTextActor);
ren1->AddViewProp (kleinTextActor);
ren1->AddViewProp (fig8KleinTextActor);
ren1->AddViewProp (mobiusTextActor);
ren1->AddViewProp (superToroidTextActor);
ren1->AddViewProp (superEllipsoidTextActor);
ren1->AddViewProp (splineTextActor);
ren1->AddViewProp (spline2TextActor);
ren1->AddViewProp (sconicTextActor);
ren1->AddViewProp (boyTextActor);
ren1->AddViewProp (crossCapTextActor);
ren1->AddViewProp (diniTextActor);
ren1->AddViewProp (enneperTextActor);
ren1->AddViewProp (ellipsoidTextActor);
ren1->AddViewProp (randomHillsTextActor);
ren1->AddViewProp (romanTextActor);
ren1->ResetCamera();
ren1->SetBackground(0.7, 0.8, 1);
renWin->SetSize(700,700);
renWin->Render();
iren->Start();
ren1->Delete();
iren->Delete();
renWin->Delete();
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -