[vtkusers] Problem with "Compute Gaussian, Mean, Minm and Max Curvatures" example

Bill Lorensen bill.lorensen at gmail.com
Tue Aug 26 16:07:14 EDT 2014


Try this. It uses a parametric torus. Something strange is going on
with your torus:

#include <vtkSmartPointer.h>

#include <vtkCurvatures.h>

#include <vtkLookupTable.h>
#include <vtkColorTransferFunction.h>
#include <vtkColorSeries.h>

#include <vtkPointData.h>

#include <vtkPolyDataMapper.h>
#include <vtkActor.h>
#include <vtkScalarBarActor.h>
#include <vtkRenderWindow.h>
#include <vtkRenderer.h>
#include <vtkRenderWindowInteractor.h>
#include <vtkParametricFunctionSource.h>
#include <vtkParametricTorus.h>

int main(int argc, char *argv[])
{
   vtkSmartPointer<vtkParametricTorus> parametricObject =
vtkSmartPointer<vtkParametricTorus>::New();
  parametricObject->SetRingRadius(0.5);
  parametricObject->SetCrossSectionRadius(.25);

  vtkSmartPointer<vtkParametricFunctionSource> parametricFunctionSource =
    vtkSmartPointer<vtkParametricFunctionSource>::New();
  parametricFunctionSource->SetParametricFunction(parametricObject);
  parametricFunctionSource->Update();

 // Create a polydata
  vtkSmartPointer<vtkCurvatures> curvaturesFilter =
    vtkSmartPointer<vtkCurvatures>::New();
  curvaturesFilter->SetInputConnection(parametricFunctionSource->GetOutputPort());
  curvaturesFilter->SetCurvatureTypeToGaussian();
  curvaturesFilter->Update();

  // Get scalar range from command line if present, otherwise use
  // range of computed curvature
  double scalarRange[2];
  if (argc >= 4)
    {
    scalarRange[0] = atof(argv[2]);
    scalarRange[1] = atof(argv[3]);
    }
  else
    {
    curvaturesFilter->GetOutput()->GetScalarRange(scalarRange);
    }

  int scheme = 16;
  if (argc >= 5)
    {
    scheme = atoi(argv[4]);
    }

  // Build a lookup table
  vtkSmartPointer<vtkColorSeries> colorSeries =
    vtkSmartPointer<vtkColorSeries>::New();
  colorSeries->SetColorScheme(scheme);
  std::cout << "Using color scheme #: "
            << colorSeries->GetColorScheme() << " is "
            << colorSeries->GetColorSchemeName() << std::endl;

  vtkSmartPointer<vtkColorTransferFunction> lut =
    vtkSmartPointer<vtkColorTransferFunction>::New();
  lut->SetColorSpaceToHSV();

  // Use a color series to create a transfer function
  int numColors = colorSeries->GetNumberOfColors();
  for (int i = 0; i < numColors; i++)
    {
      vtkColor3ub color = colorSeries->GetColor(i);
    double dColor[3];
    dColor[0] = static_cast<double> (color[0]) / 255.0;
    dColor[1] = static_cast<double> (color[1]) / 255.0;
    dColor[2] = static_cast<double> (color[2]) / 255.0;
    double t = scalarRange[0] + (scalarRange[1] - scalarRange[0])
      / (numColors - 1) * i;
    lut->AddRGBPoint(t, dColor[0], dColor[1], dColor[2]);
    }

  // Create a mapper and actor
  vtkSmartPointer<vtkPolyDataMapper> mapper =
    vtkSmartPointer<vtkPolyDataMapper>::New();
  mapper->SetInputConnection(curvaturesFilter->GetOutputPort());
  mapper->SetLookupTable(lut);
  mapper->SetScalarRange(scalarRange);

  vtkSmartPointer<vtkActor> actor =
    vtkSmartPointer<vtkActor>::New();
  actor->SetMapper(mapper);

  // Create a scalar bar
  vtkSmartPointer<vtkScalarBarActor> scalarBar =
    vtkSmartPointer<vtkScalarBarActor>::New();
  scalarBar->SetLookupTable(mapper->GetLookupTable());
  scalarBar->SetTitle(
    curvaturesFilter->GetOutput()->GetPointData()->GetScalars()->GetName());
  scalarBar->SetNumberOfLabels(5);

  // Create a renderer, render window, and interactor
  vtkSmartPointer<vtkRenderer> renderer =
    vtkSmartPointer<vtkRenderer>::New();
  vtkSmartPointer<vtkRenderWindow> renderWindow =
    vtkSmartPointer<vtkRenderWindow>::New();
  renderWindow->AddRenderer(renderer);
  vtkSmartPointer<vtkRenderWindowInteractor> renderWindowInteractor =
    vtkSmartPointer<vtkRenderWindowInteractor>::New();
  renderWindowInteractor->SetRenderWindow(renderWindow);

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

  renderer->SetBackground(.1, .2, .3); // Background color blue

  // Render and interact
  renderWindow->Render();
  renderWindowInteractor->Start();

  return EXIT_SUCCESS;
}

On Tue, Aug 26, 2014 at 3:46 PM, Bill Lorensen <bill.lorensen at gmail.com> wrote:
> That is a good reference. So it seems the gaussian curvature in VTK
> may have a problem.
>
>
> On Tue, Aug 26, 2014 at 3:37 PM, Sky77 <Joan.Hensen at outlook.de> wrote:
>> Unfortunately i haven't the wikipedia link. I searched with google for an
>> appropriate visualization of the torus. But i have found something likely.
>> You can find a similar visualization on page 2 of  this pdf file
>> <http://www.win.tue.nl/~rvhassel/Onderwijs/Tensor-ConTeX-Bib/Examples-diff-geom/Torus-diff-geom/curv-torus.pdf>
>> .
>>
>>
>>
>>
>> --
>> View this message in context: http://vtk.1045678.n5.nabble.com/Problem-with-Compute-Gaussian-Mean-Minm-and-Max-Curvatures-example-tp5728377p5728409.html
>> Sent from the VTK - Users mailing list archive at Nabble.com.
>> _______________________________________________
>> Powered by www.kitware.com
>>
>> Visit other Kitware open-source projects at http://www.kitware.com/opensource/opensource.html
>>
>> Please keep messages on-topic and check the VTK FAQ at: http://www.vtk.org/Wiki/VTK_FAQ
>>
>> Follow this link to subscribe/unsubscribe:
>> http://public.kitware.com/mailman/listinfo/vtkusers
>
>
>
> --
> Unpaid intern in BillsBasement at noware dot com



-- 
Unpaid intern in BillsBasement at noware dot com


More information about the vtkusers mailing list