From d41abf64aa645870ac727d42b839a6be02d17139 Mon Sep 17 00:00:00 2001 From: Andrew Maclean <andrew.amaclean@gmail.com> Date: Fri, 13 Oct 2017 13:53:52 +1100 Subject: [PATCH] Adding options for display. --- src/Cxx/Rendering/WalkCow.cxx | 55 ++++++++++++++++----------------- src/Python/Rendering/WalkCow.py | 39 ++++++++++++----------- 2 files changed, 48 insertions(+), 46 deletions(-) diff --git a/src/Cxx/Rendering/WalkCow.cxx b/src/Cxx/Rendering/WalkCow.cxx index f64f5bcee7c..859cbf9a391 100644 --- a/src/Cxx/Rendering/WalkCow.cxx +++ b/src/Cxx/Rendering/WalkCow.cxx @@ -73,7 +73,7 @@ int main(int argc, char* argv[]) { std::cout << "Usage: " << argv[0] << " filename [figure]" << std::endl; std::cout << "where: filename is the file cow.g" << std::endl; - std::cout << " figure is 0, 1, 0r 2, default 0" << std::endl; + std::cout << " figure is 0, 1, or 2, default 0" << std::endl; return EXIT_FAILURE; } @@ -156,19 +156,19 @@ int main(int argc, char* argv[]) ren->SetBackground(colors->GetColor3d("BkgColor2").GetData()); switch (figure) { - default: - case 0: - Rotate_V_0(cowActor, ren, renWin); - Rotate_V_V(cowActor, ren, renWin); - // Walk() needs to go after Rotate_V_0() or Rotate_V_V(). - Walk(cowActor, ren, renWin); - break; - case 1: - Rotate_V_0(cowActor, ren, renWin); - break; - case 2: - Rotate_V_V(cowActor, ren, renWin); - break; + default: + case 0: + Rotate_V_0(cowActor, ren, renWin); + Rotate_V_V(cowActor, ren, renWin); + // Walk() needs to go after Rotate_V_0() or Rotate_V_V(). + Walk(cowActor, ren, renWin); + break; + case 1: + Rotate_V_0(cowActor, ren, renWin); + break; + case 2: + Rotate_V_V(cowActor, ren, renWin); + break; } // Interact with data. @@ -354,14 +354,14 @@ void Rotate_V_0(vtkActor* cowActor, vtkRenderer* ren, vtkRenderWindow* renWin) Screenshot("Fig3-33a.png", renWin); renWin->EraseOn(); // Put the cow back on the origin. - for (int idx = 0; idx < 6; idx++) - { - cowActor->RotateWXYZ(-60, 2.19574, -1.42455, -0.0331036); - } - cowActor->SetUserMatrix(cowPos->GetMatrix()); - ren->GetActiveCamera()->SetPosition(0, 0, 1); - ren->GetActiveCamera()->SetViewUp(0, 1, 0); - ren->ResetCamera(); + // for (int idx = 0; idx < 6; idx++) + //{ + // cowActor->RotateWXYZ(-60, 2.19574, -1.42455, -0.0331036); + //} + // cowActor->SetUserMatrix(cowPos->GetMatrix()); + // ren->GetActiveCamera()->SetPosition(0, 0, 1); + // ren->GetActiveCamera()->SetViewUp(0, 1, 0); + // ren->ResetCamera(); } void Rotate_V_V(vtkActor* cowActor, vtkRenderer* ren, vtkRenderWindow* renWin) @@ -404,11 +404,11 @@ void Rotate_V_V(vtkActor* cowActor, vtkRenderer* ren, vtkRenderWindow* renWin) Screenshot("Fig3-33b.png", renWin); renWin->EraseOn(); // Put the cow back on the origin. - for (int idx = 0; idx < 6; idx++) - { - cowActor->RotateWXYZ(-60, 2.19574, -1.42455, -0.0331036); - } - cowActor->SetUserMatrix(cowPos->GetMatrix()); + // for (int idx = 0; idx < 6; idx++) + //{ + // cowActor->RotateWXYZ(-60, 2.19574, -1.42455, -0.0331036); + //} + // cowActor->SetUserMatrix(cowPos->GetMatrix()); } void Walk(vtkActor* cowActor, vtkRenderer* ren, vtkRenderWindow* renWin) @@ -494,5 +494,4 @@ void Screenshot(std::string fileName, vtkRenderWindow* renWin) writer->SetInputConnection(windowToImageFilter->GetOutputPort()); writer->Write(); } - } diff --git a/src/Python/Rendering/WalkCow.py b/src/Python/Rendering/WalkCow.py index f6b2cb6d444..d29ffaf2ce4 100644 --- a/src/Python/Rendering/WalkCow.py +++ b/src/Python/Rendering/WalkCow.py @@ -6,7 +6,7 @@ import vtk def main(): - file_name = get_program_parameters() + file_name, figure = get_program_parameters() colors = vtk.vtkNamedColors() # Set the background color. Match those in VTKTextbook.pdf. @@ -58,9 +58,6 @@ def main(): cowAxes.VisibilityOn() renWin.Render() - # A general comment: - # EraseOff() has to be called after a Render() call to work in the desired way. - # Activate this if you want to see the Position and Focal point. # ren.GetActiveCamera().AddObserver('ModifiedEvent', CameraModifiedCallback) @@ -71,10 +68,15 @@ def main(): Rotate_XY(cowActor, ren, renWin) ren.SetBackground(colors.GetColor3d("BkgColor2")) - Rotate_V_0(cowActor, ren, renWin) - Rotate_V_V(cowActor, ren, renWin) - # Walk() needs to go after Rotate_V_0() or Rotate_V_V(). - Walk(cowActor, ren, renWin) + if figure == 1: + Rotate_V_0(cowActor, ren, renWin) + elif figure == 2: + Rotate_V_V(cowActor, ren, renWin) + else: + Rotate_V_0(cowActor, ren, renWin) + Rotate_V_V(cowActor, ren, renWin) + # Walk() needs to go after Rotate_V_0() or Rotate_V_V(). + Walk(cowActor, ren, renWin) # Interact with data. renWin.EraseOff() @@ -90,8 +92,9 @@ def get_program_parameters(): ''' parser = argparse.ArgumentParser(description=description, epilog=epilogue) parser.add_argument('filename', help='The file cow.g.') + parser.add_argument('figure', default=0, type=int, nargs='?', help='The particular rotation that you want to view.') args = parser.parse_args() - return args.filename + return args.filename, args.figure """ @@ -264,12 +267,12 @@ def Rotate_V_0(cowActor, ren, renWin): Screenshot("Fig3-33a.png", renWin) renWin.EraseOn() # Put the cow back on the origin. - for idx in range(0, 6): - cowActor.RotateWXYZ(-60, 2.19574, -1.42455, -0.0331036) - cowActor.SetUserMatrix(cowPos.GetMatrix()) - ren.GetActiveCamera().SetPosition(0, 0, 1) - ren.GetActiveCamera().SetViewUp(0, 1, 0) - ren.ResetCamera() + # for idx in range(0, 6): + # cowActor.RotateWXYZ(-60, 2.19574, -1.42455, -0.0331036) + # cowActor.SetUserMatrix(cowPos.GetMatrix()) + # ren.GetActiveCamera().SetPosition(0, 0, 1) + # ren.GetActiveCamera().SetViewUp(0, 1, 0) + # ren.ResetCamera() def Rotate_V_V(cowActor, ren, renWin): @@ -306,9 +309,9 @@ def Rotate_V_V(cowActor, ren, renWin): Screenshot("Fig3-33b.png", renWin) renWin.EraseOn() # Put the cow back on the origin. - for idx in range(0, 6): - cowActor.RotateWXYZ(-60, 2.19574, -1.42455, -0.0331036) - cowActor.SetUserMatrix(cowPos.GetMatrix()) + # for idx in range(0, 6): + # cowActor.RotateWXYZ(-60, 2.19574, -1.42455, -0.0331036) + # cowActor.SetUserMatrix(cowPos.GetMatrix()) def Walk(cowActor, ren, renWin): -- GitLab