[vtkusers] Problems reading EnSight data (c++)

hedicu hedicu at gmail.com
Tue Nov 20 16:06:25 EST 2007


Hi all,

I tried to translate this tcl 
http://public.kitware.com/cgi-bin/viewcvs.cgi/*checkout*/Graphics/Testing/Tcl/EnSight6Elements.tcl?root=VTK&content-type=text/plain
example 
into c++ and the compiler says that the SetDefaultExecutivePrototype
method is protected in the vtkAlgorithm class. So i wrote a small
subclass of vtkAlgorithm and now I can call that function. The problem
I get now during runtime is

ERROR: In $VTK/Filtering/vtkDemandDrivenPipeline.cxx, line 710
vtkCompositeDataPipeline (0x15128d0): Input port 0 of algorithm
vtkGeometryFilter(0x1512710) has 0 connections but is not optional.

Do you have any idea of what am I doing wrong?

Here is the code:

#include <vtkRenderer.h>
#include <vtkCarbonRenderWindow.h>
#include <vtkGenericEnSightReader.h>
#include <vtkEnSightGoldReader.h>
#include <vtkCompositeDataPipeline.h>
#include <vtkGeometryFilter.h>
#include <vtkArrayCalculator.h>
#include <vtkHierarchicalPolyDataMapper.h>
#include <vtkActor.h>

#include "/home/diez/libspcnav/vtkSpcNavInteractor.h"


class MyAlgorithm : public vtkAlgorithm {

       public:

       MyAlgorithm() {}
       ~MyAlgorithm(){}

       static void SetDefaultExecutivePrototype(vtkExecutive* proto){

               {
 if (MyAlgorithm::DefaultExecutivePrototype == proto)
   {
   return;
   }
 if (MyAlgorithm::DefaultExecutivePrototype)
   {
   MyAlgorithm::DefaultExecutivePrototype->UnRegister(0);
   MyAlgorithm::DefaultExecutivePrototype = 0;
   }
 proto->Register(0);
 MyAlgorithm::DefaultExecutivePrototype = proto;
               }

       }
};


int main() {

// create a rendering window and renderer
vtkRenderer *ren1 = vtkRenderer::New();
vtkCarbonRenderWindow *renWin = vtkCarbonRenderWindow::New();
   renWin->AddRenderer(ren1);
   renWin->StereoCapableWindowOn();

vtkSpcNavInteractor *spcnav = new vtkSpcNavInteractor();
       spcnav->SetRenderWindow(renWin);
       spcnav->SetRotationVelocity(0.00008,0.00008,0.00008);
       spcnav->SetTranslationVelocity(0.008,0.009,0.008);

vtkEnSightGoldReader *reader = vtkEnSightGoldReader::New();
// Make sure all algorithms use the composite data pipeline
vtkCompositeDataPipeline *cdp = vtkCompositeDataPipeline::New();

//MyAlgorithm *myalg = new MyAlgorithm();
MyAlgorithm::SetDefaultExecutivePrototype(cdp);
cdp->Delete();

   reader->SetCaseFileName("$vtkdata/Data/EnSight/elements6.case");
   reader->Update();

vtkGeometryFilter *geom = vtkGeometryFilter::New();
   geom->SetInputConnection(reader-> GetOutputPort());

vtkArrayCalculator *calc = vtkArrayCalculator::New();
   calc-> SetInputConnection(geom-> GetOutputPort());
   calc-> SetAttributeModeToUsePointData();
   calc-> SetFunction("pointCVectors_r . pointCVectors_i + pointScalars");
   calc-> AddScalarArrayName("pointScalars", 0);
   calc-> AddVectorArrayName("pointCVectors_r", 0, 1, 2);
   calc-> AddVectorArrayName("pointCVectors_i", 0, 1, 2);
   calc-> SetResultArrayName("test");

vtkHierarchicalPolyDataMapper *mapper =
vtkHierarchicalPolyDataMapper::New();
   mapper-> SetInputConnection(calc-> GetOutputPort());
   mapper-> SetColorModeToMapScalars();
   mapper-> SetScalarModeToUsePointFieldData();
   mapper-> ColorByArrayComponent("test", 0);
   mapper-> SetScalarRange(0, 36000);

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

// assign our actor to the renderer
ren1-> AddActor(actor);

renWin-> Render();

spcnav->Start();
}

Thank you.

Hector.
-- 
View this message in context: http://www.nabble.com/Problems-reading-EnSight-data-%28c%2B%2B%29-tf4846379.html#a13865743
Sent from the VTK - Users mailing list archive at Nabble.com.




More information about the vtkusers mailing list