[vtkusers] [VTK] Possible bug in clipVolume2 and clipVolume3 tests

Jon Haitz Legarreta jhlegarreta at vicomtech.org
Wed Jun 11 03:47:26 EDT 2014


Hi there,
I was trying to execute the clipVolume2 example located in
Filters\General\Testing\Python (using VTK 6.1.0). I translated the code
into C++ for internal practical reasons. Please, find attached the source
and CMakeLists.txt.

However, I'd dare to say that both clipVolume2 and clipVolume3 contain a
bug. The compiler complains about the following statement:

  dataset->SetDataSet(sample->GetOutput());

The function SetDataSet expects a vtkDataSet * argument type and gets
a vtkImageData
* argument type.

I guess the Python examples fails at this point as well.

Is this a know bug or am I missing something?

Thank you,
JON HAITZ
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.vtk.org/pipermail/vtkusers/attachments/20140611/ed4e1164/attachment.html>
-------------- next part --------------
cmake_minimum_required(VERSION 2.8)
 
PROJECT(clipVolume)
 
find_package(VTK REQUIRED)
include(${VTK_USE_FILE})
 
add_executable(clipVolume clipVolume2.cxx)
 
if(VTK_LIBRARIES)
  target_link_libraries(clipVolume ${VTK_LIBRARIES})
else()
  target_link_libraries(clipVolume vtkHybrid vtkWidgets)
endif()
-------------- next part --------------
/*=========================================================================

  Program:   Visualization Toolkit
  Module:    clipVolume2.cxx

  Copyright (c) Ken Martin, Will Schroeder, Bill Lorensen
  All rights reserved.
  See Copyright.txt or http://www.kitware.com/Copyright.htm for details.

     This software is distributed WITHOUT ANY WARRANTY; without even
     the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
     PURPOSE.  See the above copyright notice for more information.

=========================================================================*/


// 
// This demonstrates how to generate a 3D tetrahedra mesh from a volume. This example
// differs from clipVolume in that the mesh is generated within a range of contour
// values.
// 
 
 
// VTK includes
#include <vtkActor.h>
#include <vtkDataSetMapper.h>
#include <vtkClipVolume.h>
#include <vtkImplicitDataSet.h>
#include <vtkImplicitWindowFunction.h>
#include <vtkOutlineFilter.h>
#include <vtkPolyDataMapper.h>
#include <vtkProperty.h>
#include <vtkQuadric.h>
#include <vtkRenderer.h>
#include <vtkRenderWindow.h>
#include <vtkRenderWindowInteractor.h>
#include <vtkSampleFunction.h>
#include <vtkSmartPointer.h>

 
int main(int, char *[])
{

  // Quadric definition
  vtkSmartPointer<vtkQuadric> quadric = vtkSmartPointer<vtkQuadric>::New();
  quadric->SetCoefficients(.5,1,.2,0,.1,0,0,.2,0,0);

  vtkSmartPointer<vtkSampleFunction> sample = vtkSmartPointer<vtkSampleFunction>::New();
  sample->SetSampleDimensions(20,20,20);
  sample->SetImplicitFunction(quadric);
  sample->ComputeNormalsOff();

  // Program a bandpass filter to clip a range of data. What we do is transform the
  // scalars so that values laying betweeen (minRange,maxRange) are >= 0.0; all
  // others are < 0.0
  vtkSmartPointer<vtkImplicitDataSet> dataset = vtkSmartPointer<vtkImplicitDataSet>::New();
  dataset->SetDataSet(sample->GetOutput());

  vtkSmartPointer<vtkImplicitWindowFunction> window = vtkSmartPointer<vtkImplicitWindowFunction>::New();
  window->SetImplicitFunction(dataset);
  window->SetWindowRange(0.5,1.0);
  
  // Generate tetrahedral mesh
  vtkSmartPointer<vtkClipVolume> clip = vtkSmartPointer<vtkClipVolume>::New();
  clip->SetInputConnection(sample->GetOutputPort());
  clip->SetClipFunction(window);
  clip->SetValue(0.0);
  clip->GenerateClippedOutputOff();

  vtkSmartPointer<vtkDataSetMapper> clipMapper = vtkSmartPointer<vtkDataSetMapper>::New();
  clipMapper->SetInputConnection(clip->GetOutputPort());
  clipMapper->ScalarVisibilityOff();

  vtkSmartPointer<vtkActor> clipActor = vtkSmartPointer<vtkActor>::New();
  clipActor->SetMapper(clipMapper);
  clipActor->GetProperty()->SetColor(.5,.5,.5);

  // Create outline
  vtkSmartPointer<vtkOutlineFilter> outline = vtkSmartPointer<vtkOutlineFilter>::New();

  // Outline SetInputData [clip GetInput]
  outline->SetInputConnection(sample->GetOutputPort());

  vtkSmartPointer<vtkPolyDataMapper> outlineMapper = vtkSmartPointer<vtkPolyDataMapper>::New();
  outlineMapper->SetInputConnection(outline->GetOutputPort());

  vtkSmartPointer<vtkActor> outlineActor = vtkSmartPointer<vtkActor>::New();
  outlineActor->SetMapper(outlineMapper);
  outlineActor->GetProperty()->SetColor(0,0,0);

  // Define graphics objects
  vtkSmartPointer<vtkRenderer> ren1 = vtkSmartPointer<vtkRenderer>::New();

  vtkSmartPointer<vtkRenderWindow>renWin = vtkSmartPointer<vtkRenderWindow>::New();
  renWin->SetMultiSamples(0);
  renWin->AddRenderer(ren1);

  vtkSmartPointer<vtkRenderWindowInteractor> iren = vtkSmartPointer<vtkRenderWindowInteractor>::New();
  iren->SetRenderWindow(renWin);
  ren1->SetBackground(1,1,1); // white
  ren1->AddActor(clipActor);
  ren1->AddActor(outlineActor);
  iren->Initialize();

  renWin->Render();
  iren->Start();
 
  return EXIT_SUCCESS;
}


More information about the vtkusers mailing list