lorensen / VTKExamples

The VTK examples, formerly hosted on media wiki
Apache License 2.0
350 stars 157 forks source link

Add cxx animation example #556

Closed chakravarthi589 closed 5 years ago

chakravarthi589 commented 5 years ago

@ajpmaclean : Please review.

lorensen commented 5 years ago

The example never stops. Please have it stop after 360 degrees.

Remove #include and any other unsed includes.

Make the window a little bigger, say 640, 480.

Tnanks

ajpmaclean commented 5 years ago

Also in VTKExamples/src/Cxx there is a file called .clang-format that specifies the formatting for the Kitware standard formatting for C++. If you don't know how to use clang-format or it is not built in to your editor, I can fix the formatting once it is merged.

chakravarthi589 commented 5 years ago

@lorensen . @ajpmaclean:

  1. Sphere Rotation stops.
  2. Unused Includes are removed
  3. Window size changed to 640,480
  4. Unwanted comments are removed.

I have enabled the built in clang-format in my editor. but am not sure whether the formatting is as expected.

Please review.

ajpmaclean commented 5 years ago

For some reason your indentation seems to be 8 spaces instead of two spaces, so the formatting is not correct, I don' t think it picked up the .clang-format file. Please refer to Guidelines and look at existing examples.

chakravarthi589 commented 5 years ago

@ajpmaclean : I'll try again to fix the indentation issue.

chakravarthi589 commented 5 years ago

Is this fine now ?

ajpmaclean commented 5 years ago
  1. Why did you add #include <vtkAnimationScene.h>? I don't see it being used anywhere in the code.
  2. Your formatting is still not correct, some of your lines are too long. You can download clang-format and use the supplied .clang-format to easily format your code if your editor is not supporting it. See Clang 9 documentation for how to use it. It is worth setting up!
chakravarthi589 commented 5 years ago

Please review now. I've followed your inputs.

ajpmaclean commented 5 years ago

You need to re-run ctest as the images are different.

Image differencing failed to produce an image because images are different size:
Valid image: 230, 229, 1
Test image: 640, 480, 1
<DartMeasurement name="WallTime" type="numeric/double">0.35</DartMeasurement>
<DartMeasurement name="CPUTime" type="numeric/double">0.351</DartMeasurement>
<end of output>
Test time =   5.62 sec
ajpmaclean commented 5 years ago

There may be a problem with your formatting, when I run clang-format -i RotatingSphere.cxx I get:

#include <vtkActor.h>
#include <vtkNamedColors.h>
#include <vtkPolyDataMapper.h>
#include <vtkProperty.h>
#include <vtkRenderWindow.h>
#include <vtkRenderWindowInteractor.h>
#include <vtkRenderer.h>
#include <vtkSmartPointer.h>
#include <vtkSphereSource.h>

class vtkTimerCallback2 : public vtkCommand
{
public:
  int timerId;
  static vtkTimerCallback2* New()
  {
    vtkTimerCallback2* cb = new vtkTimerCallback2;
    cb->TimerCount = 0;
    return cb;
  }
  virtual void Execute(vtkObject* caller, unsigned long eventId,
                       void* vtkNotUsed(callData))
  {
    vtkRenderWindowInteractor* iren =
        dynamic_cast<vtkRenderWindowInteractor*>(caller);
    if (vtkCommand::TimerEvent == eventId)
    {
      ++this->TimerCount;
    }
    if (TimerCount < 36)
    {
      actor->RotateZ(5);
      iren->GetRenderWindow()->Render();
    }
    else
    {
      iren->DestroyTimer();
    }
  }

private:
  int TimerCount;

public:
  vtkActor* actor;
};

int main(int, char* [])
{
  vtkSmartPointer<vtkNamedColors> colors =
      vtkSmartPointer<vtkNamedColors>::New();

  // Create a sphere
  vtkSmartPointer<vtkSphereSource> sphereSource =
      vtkSmartPointer<vtkSphereSource>::New();
  sphereSource->SetCenter(0.0, 0.0, 0.0);
  sphereSource->SetRadius(1.0);
  sphereSource->SetThetaResolution(15);
  sphereSource->SetPhiResolution(15);
  sphereSource->Update();

  // Create a mapper and actor
  vtkSmartPointer<vtkPolyDataMapper> mapper =
      vtkSmartPointer<vtkPolyDataMapper>::New();
  mapper->SetInputConnection(sphereSource->GetOutputPort());
  vtkSmartPointer<vtkActor> actor = vtkSmartPointer<vtkActor>::New();
  actor->SetMapper(mapper);
  actor->RotateX(90);
  actor->GetProperty()->SetRepresentationToWireframe();

  // Create a renderer, render window, and interactor
  vtkSmartPointer<vtkRenderer> renderer = vtkSmartPointer<vtkRenderer>::New();
  vtkSmartPointer<vtkRenderWindow> renderWindow =
      vtkSmartPointer<vtkRenderWindow>::New();
  renderWindow->AddRenderer(renderer);
  renderWindow->SetSize(640, 480);

  vtkSmartPointer<vtkRenderWindowInteractor> renderWindowInteractor =
      vtkSmartPointer<vtkRenderWindowInteractor>::New();
  renderWindowInteractor->SetRenderWindow(renderWindow);

  // Add the actor to the scene
  renderer->AddActor(actor);

  renderer->SetBackground(colors->GetColor3d("Seashell").GetData());
  // Render and interact
  renderWindow->Render();

  // Initialize must be called prior to creating timer events.
  renderWindowInteractor->Initialize();

  // Sign up to receive TimerEvent
  vtkSmartPointer<vtkTimerCallback2> cb =
      vtkSmartPointer<vtkTimerCallback2>::New();
  cb->actor = actor;

  renderWindowInteractor->AddObserver(vtkCommand::TimerEvent, cb);
  int timerId = renderWindowInteractor->CreateRepeatingTimer(100);
  cb->timerId = timerId;

  // Start the interaction and timer
  renderWindowInteractor->Start();

  return EXIT_SUCCESS;
}
chakravarthi589 commented 5 years ago

@ajpmaclean : Please review now.

ajpmaclean commented 5 years ago

Looking good! Thanks. These examples showcase VTK and must inspire, so the images must look good and the code formatting has to be consistent.

chakravarthi589 commented 5 years ago

@ajpmaclean: Thank you for your inputs and valuable time to review the examples. Such great work by you and @lorensen. VTK is helping a lot of users like me to learn visualization concepts very effectively.