[vtkusers] Help with vtkHierarchicalDataSet

Sunil Suram sunils at iastate.edu
Thu Jun 7 12:14:52 EDT 2007


I called the Update function on filter1 and I get the following 
error. I have included the complete code below.
================================================================
vtkStreamingDemandDrivenPipeline (0x9f128f0): Input port 0 of 
algorithm vtkAppendPolyData(0x9f112e0) has 0 connections but is not optional.
================================================================
Thanks.
Sunil

#include "vtkContourFilter.h"
#include "vtkHierarchicalDataSet.h"
#include "vtkHierarchicalDataSetGeometryFilter.h"
#include "vtkPolyData.h"
#include "vtkXMLMultiGroupDataWriter.h"
#include "vtkXMLHierarchicalDataReader.h"
#include "vtkPointData.h"
#include "vtkHierarchicalDataSetAlgorithm.h"
#include "vtkPolyDataNormals.h"
#include <iostream>
using namespace std;
int main(int argc, char* argv[])
{
    //read in HDS
    vtkXMLHierarchicalDataReader* reader = vtkXMLHierarchicalDataReader::New();
    reader->SetFileName( "mb.vtu" );
    reader->Update();

    vtkMultiGroupDataSet* mgd;
    mgd = (reader->GetOutput(0));
    cout<<"Getting number of groups :"<<endl;
    cout<<"Number of groups :"<<mgd->GetNumberOfGroups()<<endl;
    int check = 0;
    for ( int grp=0;grp<mgd->GetNumberOfGroups();grp++ )
    {
       for ( int ds=0;ds<mgd->GetNumberOfDataSets(grp);ds++ )
       {
          //activate scalar "Density"
          check = dynamic_cast<vtkDataSet*>(mgd->GetDataSet(grp,ds))->
                GetPointData()->SetActiveScalars( "Density" );
          cout<<"CHECK is :"<<check<<endl;
          if ( check != -1 )
             cout<<"Group :"<<grp<<" Dataset :"<<ds<<" set Density"<<endl;
       }
    }


    ////////////setup pipelines
    vtkHierarchicalDataSetAlgorithm* alg =
          vtkHierarchicalDataSetAlgorithm::New();
    alg->SetInput( 0, mgd );
    alg->Update();


    vtkHierarchicalDataSetGeometryFilter* filter1 =
                vtkHierarchicalDataSetGeometryFilter::New( );
    filter1->SetInputConnection( 0, alg->GetOutputPort(0) );
    filter1->Update();

    vtkContourFilter *contour = vtkContourFilter::New();
    contour->SetInputConnection( 0, filter1->GetOutputPort(0) );
    contour->SetValue( 0, 0.2 );
    contour->UseScalarTreeOff();

    vtkPolyDataNormals *normals = vtkPolyDataNormals::New();
    normals->SetInputConnection( 0, contour->GetOutputPort(0) );

    vtkHierarchicalDataSetGeometryFilter* filter =
              vtkHierarchicalDataSetGeometryFilter::New( );
    filter->SetInput( normals->GetOutput(0) );

    int numPolys = filter->GetOutput()->GetNumberOfPolys();
    std::cout << "     The number of polys is "<< numPolys << std::endl;

    //clean up
    reader->Delete();
    return 0;
}



At 09:09 AM 6/7/2007, Marc Cotran wrote:
>Hi Sunil,
>
>I'm not sure if this will help you as I've no experience with that 
>specific filter, but you could try calling Update() on it before 
>your std::cout call. VTK pipelines are largely demand driven, so if 
>you don't render the result of the pipeline, for example, the filter 
>does not actually execute. Calling Update() forces the object to run.
>
>Marc
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.vtk.org/pipermail/vtkusers/attachments/20070607/b5750559/attachment.htm>


More information about the vtkusers mailing list