[vtkusers] Migration to VTK 6.x

Berk Geveci berk.geveci at kitware.com
Tue Sep 15 10:29:13 EDT 2015


Hi Yan,

I would like to suggest that someone who  is more familiar with this code
joins in on this discussion. This is not a straightforward replacement of
one class with another. Also, please keep the discussion on the mailing
list.

Best,
-berk

On Tue, Sep 15, 2015 at 10:12 AM, Yan Liu <liuyanbc157 at gmail.com> wrote:

> Hi, Berk,
> This is one Code with .h and .cxx , which should be fixed for VTK 6.2.
>
> I'm not sure what is the destination to use these codes, because i'm a
> beginner for this software.
> *vtkLocalTemporalNew.h:*
>
> #ifndef __vtkLocalTemporalNew_h
> #define __vtkLocalTemporalNew_h
>
> #include "vtkTemporalDataSetAlgorithm.h"
> #include "vtkStreamingDemandDrivenPipeline.h"
> #include <vtkstd/vector>
>
> //class vtkCompositeDataSet;
> class vtkDataSet;
> class vtkDataObject;
> //class vtkHierarchicalBoxDataSet;
> //class vtkIntArray;
> //class vtkRectilinearGrid;
> //class vtkUniformGrid;
>
>
> struct dim_item {
>   unsigned int dim; // dimension count 1,2,3...
>   unsigned int number; // number of different points in this dimension
>   char * name; // name of dimension
>   struct dim_item* next;
> };
>
> struct timestep_item {
>   double time; //
>   struct timestep_item* next;
> };
>
> class VTK_PARALLEL_EXPORT vtkLocalTemporalNew : public
> vtkTemporalDataSetAlgorithm
> {
> public:
>   static vtkLocalTemporalNew *New();
>   vtkTypeRevisionMacro(vtkLocalTemporalNew,vtkTemporalDataSetAlgorithm);
>   void PrintSelf(ostream& os, vtkIndent indent);
>
>   void AddDimension(char * dimName, double planeValue = 0.0);
>   char * GetDimName(int dim);
>   int GetDimCount();
>   //void SetInputData(vtkTemporalDataSet *dataset);
>   void SetStepData(double ident[], unsigned int dim, vtkDataObject* dobj);
>   void SetStepData(vtkDataObject* dobj);
>   void ReplaceStepData(double ident[], unsigned int dim, vtkDataObject*
> dobj);
>   void ReplaceStepData(vtkDataObject* dobj);
>   int GetIndex(double ident[]);
>   void SetParameter(unsigned int dim, double param);
>   void UpdateParameter(vtkStreamingDemandDrivenPipeline *sdd);
>
> protected:
>   vtkLocalTemporalNew();
>   ~vtkLocalTemporalNew();
>
>   // Description:
>   // This is called by the superclass.
>   // This is the method you should override.
>   virtual int RequestInformation(vtkInformation *request,
>                                  vtkInformationVector **inputVector,
>                                  vtkInformationVector *outputVector);
>
>   // Description:
>   // This is called by the superclass.
>   // This is the method you should override.
>   virtual int RequestData(vtkInformation *request,
>                           vtkInformationVector **inputVector,
>                           vtkInformationVector *outputVector);
>
>   //vtkTemporalDataSet *inputdata;
>   vtkTemporalDataSet *dataset;
>   dim_item *dimlist;
>   timestep_item *timesteps;
>   double *parameterArr;
>   unsigned int *parameterArrInt;
>
>   void AppendTimestepsReverse(timestep_item *timestep);
>   void AppendTimestep(double time);
>   void ClearTimeSteps();
>
> private:
>   vtkLocalTemporalNew(const vtkLocalTemporalNew&);  // Not implemented.
>   void operator=(const vtkLocalTemporalNew&);  // Not implemented.
> //BTX
>   vtkstd::vector< vtkstd::vector<double> > dataparams;
>   char errormessage;
> //ETX
>
> };
>
>
> #endif
>
> *And another:*
> *vtkLocalTemporalNew.cxx*
>
> *#*include "vtkLocalTemporalNew.h"
>
> //#include "vtkAMRBox.h"
> //#include "vtkCellData.h"
> //#include "vtkCompositeDataIterator.h"
> //#include "vtkDoubleArray.h"
> //#include "vtkHierarchicalBoxDataSet.h"
> //#include "vtkImageMandelbrotSource.h"
> #include "vtkInformation.h"
> #include "vtkInformationVector.h"
> //#include "vtkIntArray.h"
> //#include "vtkMath.h"
> #include "vtkMultiBlockDataSet.h"
> #include "vtkObjectFactory.h"
> //#include "vtkPointData.h"
> //#include "vtkRectilinearGrid.h"
> #include "vtkStreamingDemandDrivenPipeline.h"
> #include "vtkTemporalDataSet.h" //has to be changed******
> //#include "vtkUniformGrid.h"
> //#include "vtkUnsignedCharArray.h"
> #include "vtkPolyData.h"
> #include <vtkSmartPointer.h>
> #include <vtkStructuredGrid.h>
>
> //#include "vtkExtractCTHPart.h" // for the BOUNDS key
>
> #include <assert.h>
> vtkCxxRevisionMacro(vtkLocalTemporalNew, "$Revision$");
> vtkStandardNewMacro(vtkLocalTemporalNew);
>
>
> //----------------------------------------------------------------------------
> vtkLocalTemporalNew::vtkLocalTemporalNew()
> {
>   this->SetNumberOfInputPorts(0);
>
> //  this->inputdata = vtkTemporalDataSet::New();
>   this->dataset = vtkTemporalDataSet::New();
>   this->dimlist = NULL; // contains information about dimensions in
> decreasing order
>   this->timesteps = NULL;
>   this->parameterArr = NULL; // store parameter temporarily
>   this->parameterArrInt = NULL; // store parameter temporarily
>   //this->data = 0 // will be replaced by the multidimensional array
> }
>
>
> //----------------------------------------------------------------------------
> vtkLocalTemporalNew::~vtkLocalTemporalNew()
> {
> // TODO!! Speicher von dimlist freigeben!
> // TODO!! Speicher von timesteps freigeben!
>
> }
>
> void vtkLocalTemporalNew::AddDimension(char * dimName, double planeValue)
> {
> // number: points in the new dimension
> dim_item *item = new dim_item;
> if (this->dimlist == NULL)
> {
> item->dim = 1; // first dimension -> dim = 1
> item->next = NULL;
> } else
> {
> item->dim = this->dimlist->dim + 1;
> item->next = this->dimlist;
> // add planeValue to all data
> for (int i = 0; i < this->dataparams.size(); i++)
> {
> this->dataparams[i].push_back(planeValue);
> }
> }
> item->name = dimName;
> this->dimlist = item;
> //Set the missing parameter (we have a new dimension here)
> this->SetParameter(this->dimlist->dim,planeValue);
> //(this->GetOutputPort())->Modified();
> this->Modified();
> // if (this->dimlist->dim > 1)
> // {
> // this->Update();
> // }
> }
>
> char * vtkLocalTemporalNew::GetDimName(int dim)
> {
>   dim_item *item = this->dimlist;
>   while (item != NULL)
>   {
>  if (item->dim == dim + 1)
>  {
>  vtkDebugMacro("vtkLocalTemporalNew::GetDimName:  " << item->name);
>  return item->name;
>  }
>  item = item->next;
>   }
>   vtkDebugMacro("vtkLocalTemporalNew::GetDimName: Did not find name of
> dimension "<< dim +1);
>   this->errormessage = 'vtkLocalTemporalNew::GetDimName: Did not find name
> of dimension';
>   return &this->errormessage;
> }
>
> int vtkLocalTemporalNew::GetDimCount()
> {
> return this->dimlist->dim;
> }
>
> void vtkLocalTemporalNew::SetParameter(unsigned int dim, double param)
> {
> // set parameter of dimension dim to value param
> if ((dim <= 0) or (this->dimlist == NULL)
> or (dim > this->dimlist->dim))
> {
> vtkDebugMacro("vtkLocalTemporalNew::SetParameter Wrong dimension " << dim);
> return;
> }
> if (this->parameterArr == NULL)
> {
> this->parameterArr = new double[this->dimlist->dim];
> }
> this->parameterArr[dim-1] = param;
> }
>
> void vtkLocalTemporalNew::UpdateParameter(vtkStreamingDemandDrivenPipeline
> *sdd)
> {
> // Update the pipeline according to the stored parameter
> // paramter have to be set before by calling
> vtkLocalTemporalNew::SetParameter
> vtkDebugMacro("vtkLocalTemporalNew::UpdateParameter");
> if (this->parameterArr == NULL)
> return;
> sdd->SetUpdateTimeSteps(0, this->parameterArr, this->dimlist->dim);
> this->Update();
> }
>
> void vtkLocalTemporalNew::SetStepData(vtkDataObject* dobj)
> {
> if (this->parameterArr == NULL)
> return;
>
> this->SetStepData(this->parameterArr, this->dimlist->dim, dobj);
>
> this->Modified();
> this->Update();
> }
>
> void vtkLocalTemporalNew::SetStepData(double ident[], unsigned int dim,
> vtkDataObject* dobj)
> {
> // dim should contain the length of ident
> if (dim != this->dimlist->dim)
> {
> vtkDebugMacro("vtkLocalTemporalNew::SetStepData: ERROR wrong dimension!");
> return;
> }
> // get index to store dobj
> int index = this->dataparams.size();
> // store dobj
> this->dataset->SetTimeStep(index, dobj);
> // store params
> vtkstd::vector<double> params;
> params.resize(dim);
> for (int i = 0; i < dim; i++)
> {
> params[i] = ident[i];
> }
> this->dataparams.push_back(params);
>
> }
>
> void vtkLocalTemporalNew::ReplaceStepData(vtkDataObject* dobj)
> {
> if (this->parameterArr == NULL)
> return;
>
> this->ReplaceStepData(this->parameterArr, this->dimlist->dim, dobj);
>
> this->Modified();
> this->Update();
> }
>
> void vtkLocalTemporalNew::ReplaceStepData(double ident[], unsigned int
> dim, vtkDataObject* dobj)
> {
> // dim should contain the length of ident
> if (dim != this->dimlist->dim)
> {
> vtkDebugMacro("vtkLocalTemporalNew::ReplaceStepData: ERROR wrong
> dimension!");
> return;
> }
> // get index to store dobj
> int index;
> bool match = false;
> for (int i = 0; i < this->dataparams.size(); i++)
> {
> for (int j = 0; j < dim; j++)
> {
> if ( this->dataparams[i][j] != ident[j] )
> {
> break;
> }
> index = i;
> match = true;
> }
> if (match)
> break;
> }
> if (!match)
> {
> vtkDebugMacro("vtkLocalTemporalNew::ReplaceStepData: ERROR timestep not
> found!");
> return;
> }
>
> // store dobj
> this->dataset->SetTimeStep(index, dobj);
> }
>
>
>
> int vtkLocalTemporalNew::GetIndex(double ident[])
> {
> for (int i = 0; i < this->dataparams.size(); i++)
> {
> bool ok = true;
> for (int par = 0; par < this->dataparams[i].size(); par++)
> {
> if (this->dataparams[i][par] != ident[par])
> {
> ok = false;
> }
> }
> if (ok) // found index
> {
> vtkDebugMacro("vtkLocalTemporalNew::GetIndex " <<  i);
> return i;
> }
> }
> vtkDebugMacro("vtkLocalTemporalNew::GetIndex did not found parameterset "
> << ident[0] << " " << ident[1]);
> return -1;
> }
>
> int vtkLocalTemporalNew::RequestInformation(
>   vtkInformation *request,
>   vtkInformationVector **inputVector,
>   vtkInformationVector *outputVector)
> {
>   vtkDebugMacro("vtkLocalTemporalNew::RequestInformation");
>
> if(!this->Superclass::RequestInformation(request,inputVector,outputVector))
>     {
>     return 0;
>     }
>   vtkDebugMacro("vtkLocalTemporalNew::RequestInformation 2 ");
>   vtkInformation *info=outputVector->GetInformationObject(0);
>   vtkDebugMacro("vtkLocalTemporalNew::RequestInformation 3 ");
>
>   // get time steps
>   int nrsteps = this->dataparams.size() * this->dimlist->dim;
>   double tsteps[nrsteps];
>   int count = 0;
>   for (int i = 0; i < this->dataparams.size(); i++)
>   {
>   for (int par = 0; par < this->dataparams[i].size(); par++)
>   {
>   tsteps[count] = this->dataparams[i][par];
>   count++;
>   }
>   }
>
>   info->Set(vtkStreamingDemandDrivenPipeline::TIME_STEPS(),tsteps,nrsteps);
>
>   // get time range
>   dim_item *dlist = this->dimlist;
>   double trange[this->dimlist->dim * 2];
>
>   vtkstd::vector<double> maxval(this->dimlist->dim);
>   vtkstd::vector<double> minval(this->dimlist->dim);
>
>   for (int par = 0; par < this->dimlist->dim; par++)
>   {
>  maxval[par] = this->dataparams[0][par];
>  minval[par] = this->dataparams[0][par];
>   }
>   for (int i = 1; i < this->dataparams.size(); i++)
>   {
>  for (int par = 0; par < this->dataparams[i].size(); par++)
>  {
>  if (maxval[par] < this->dataparams[i][par])
>  {
>  maxval[par] = this->dataparams[i][par];
>  }
>  if (minval[par] > this->dataparams[i][par])
>  {
>  minval[par] = this->dataparams[i][par];
>  }
>  }
>   }
>
>   for (int i = 0; i < this->dimlist->dim; i++)
>   {
>  trange[i] = minval[i];
>  trange[i+this->dimlist->dim] = maxval[i];
>   }
>
>
> info->Set(vtkStreamingDemandDrivenPipeline::TIME_RANGE(),trange,this->dimlist->dim
> * 2);
>
> //info->Set(vtkStreamingDemandDrivenPipeline::TIME_RANGE(),trange,this->dimlist->dim
> * 2);
>   vtkDebugMacro("vtkLocalTemporalNew::RequestInformation 5 " <<
> this->dimlist->dim * 2);
>
> info->Set(vtkStreamingDemandDrivenPipeline::MAXIMUM_NUMBER_OF_PIECES(),-1);
>   return 1;
> }
>
>
>
> //----------------------------------------------------------------------------
> int vtkLocalTemporalNew::RequestData(
>   vtkInformation *request,
>   vtkInformationVector **inputVector,
>   vtkInformationVector *outputVector)
> {
>   vtkInformation *info=outputVector->GetInformationObject(0);
>   vtkDebugMacro("vtkLocalTemporalNew::RequestData");
>   // get how many time steps were requested
>   int numTimeSteps =
>     info->Length(vtkStreamingDemandDrivenPipeline::UPDATE_TIME_STEPS());
>   double *timeSteps =
>     info->Get(vtkStreamingDemandDrivenPipeline::UPDATE_TIME_STEPS());
>
>   for (int j = 0; j < numTimeSteps; j++)
>   {
>   vtkDebugMacro("vtkLocalTemporalNew::RequestData timeSteps " <<
> timeSteps[j]);
>   }
>
>   // handle initial request
>   int arrlen;
>   if ((numTimeSteps == 1) and (this->dimlist->dim > 1))
>   {
>   // request for first element -> adjust length of numTimeSteps
>   arrlen = this->dimlist->dim;
>   } else
>   {
>  arrlen = numTimeSteps;
>   }
>
>   double newTimeSteps[arrlen];
>
>   if ((numTimeSteps == 1) and (this->dimlist->dim > 1))
>   {
> numTimeSteps = arrlen;
> if (this->dataparams[0].size() > 0)
> {
> // fill newTimeSteps with first dataset params
> for (int i = 0; i < numTimeSteps; i++)
> {
> newTimeSteps[i] = this->dataparams[0][i];
> }
> } else
> // fill newTimeSteps with zero params
> for (int i = 0; i < numTimeSteps; i++)
> {
> newTimeSteps[i] = 0.0;
> }
> {
>
> }
>   } else
>   {
>  // fill newTimeSteps with given data from pipeline
>  for (int i = 0; i < numTimeSteps; i++)
>  {
>  newTimeSteps[i] = timeSteps[i];
>  }
>   }
>
>   // convert 1-dim steps / points to n-dim
>   unsigned int newnum = numTimeSteps / this->dimlist->dim;
>   double newsteps[newnum][this->dimlist->dim];
>   unsigned int iter_oldsteps = 0;
>   for (int i = 0; i < newnum; i++)
>   {
>   for (int j = 0; j < this->dimlist->dim; j++)
> {
> newsteps[i][j] = newTimeSteps[iter_oldsteps];
> iter_oldsteps++;
> }
>   }
>
>   vtkDebugMacro("vtkLocalTemporalNew::RequestData 2 " << numTimeSteps);
>   vtkDataObject *doOutput=info->Get(vtkDataObject::DATA_OBJECT());
>   vtkTemporalDataSet *output = vtkTemporalDataSet::SafeDownCast(doOutput);
>
>   if(output==0)
>     {
>     vtkErrorMacro("The output is not a TemporalDataSet");
>     return 0;
>     }
>
>   if (!info->Has(vtkStreamingDemandDrivenPipeline::UPDATE_PIECE_NUMBER())
> ||
>
> !info->Has(vtkStreamingDemandDrivenPipeline::UPDATE_NUMBER_OF_PIECES()))
>     {
>     vtkErrorMacro("Expected information not found. "
>                   "Cannot provide update extent.");
>     return 0;
>     }
>   vtkDebugMacro("vtkLocalTemporalNew::RequestData 3 "  << newnum);
>
>   vtkSmartPointer<vtkStructuredGrid> unStructuredGrid =
>         vtkSmartPointer<vtkStructuredGrid>::New();
>   // now create the HierarchicalDataSet for each time step
>   int ts;
>   for (ts = 0; ts < newnum; ++ts)
>     {
>     int count = output->GetNumberOfTimeSteps();
>     int index = this->GetIndex(newsteps[ts]);
>     if (index == -1)
>     {
>     output->SetTimeStep(count, unStructuredGrid);
>     } else
>     {
>     output->SetTimeStep(count, this->dataset->GetTimeStep( index ));
>     }
>
>     vtkDebugMacro("vtkLocalTemporalNew::RequestData - write output ");
>   //  vtkDebugMacro(""<< this->inputdata->GetTimeStep( timeSteps[ts] ) );
>     vtkDebugMacro(""<< numTimeSteps );
>     vtkDebugMacro(""<< newTimeSteps[ts]);
>     }
>   output->GetInformation()->Set(vtkDataObject::DATA_TIME_STEPS(),
>                                 newTimeSteps, numTimeSteps);
>   return 1;
> }
>
>
> //----------------------------------------------------------------------------
> void vtkLocalTemporalNew::PrintSelf(ostream& os, vtkIndent indent)
> {
>   this->Superclass::PrintSelf(os,indent);
>
> //  os << indent << "NumberOfTimeSteps: " <<
> this->inputdata->GetNumberOfTimeSteps() << endl;
>   os<< endl;
> }
>
>
> 2015-09-15 15:22 GMT+02:00 Berk Geveci <berk.geveci at kitware.com>:
>
>> Dear Yan,
>>
>> I still need some more information. More about how this is all used than
>> which filters there are. That filter is no longer needed since the time
>> information is now handled differently. Instead, the functionality is
>> pushed to the consumers of the time information. They are expect to request
>> the appropriate time steps.
>>
>> Best,
>> -berk
>>
>> On Tue, Sep 15, 2015 at 9:14 AM, Ich <liuyanbc157 at gmail.com> wrote:
>>
>>> Dear Berk,
>>>
>>> Thanks for your replying.
>>> In my software, some functions like vtkTemporalSnaptoTimeStep were
>>> rewrite, named as vtkLocalSnaptoStep, but it looks like
>>> vtkTemporalSnaptoTimeStep in GitHub. With VTK 5.4 it was inherit from
>>> vtkTemporalDataSetAlgorithm. In VTK 6.2 I don’t know how to change the
>>> things in it.
>>>
>>> Thanks in advance.
>>>
>>> Yan
>>>
>>> Am 15.09.2015 um 14:48 schrieb Berk Geveci <berk.geveci at kitware.com>:
>>>
>>> Dear Yan,
>>>
>>> This somewhat depends on your use cases. We removed vtkTemporalDataSet
>>> and pushed the temporal streaming functionality to the pipeline and
>>> algorithms. It is still possible for an algorithm to ask for multiple time
>>> steps, for example by subclassing vtkMultiTimeStepAlgorithm. I can
>>> guide you better if you provide a description of how these are currently
>>> used. Also see:
>>> http://www.vtk.org/Wiki/VTK/Remove_vtkTemporalDataSet
>>>
>>> Best,
>>> -berk
>>>
>>> Best,
>>> -berk
>>>
>>> On Tue, Sep 15, 2015 at 5:36 AM, Yan <liuyanbc157 at gmail.com> wrote:
>>>
>>>> Hi, dear all,
>>>>
>>>> I'm new to VTK. My task is changing codes from VTK 5.4 to 6.2 or later
>>>> to
>>>> 6.3. But I found that some functions are removed or totally changed in
>>>> VTK
>>>> 6.x.
>>>>
>>>> Now my problem is that vtkTemporalDataSetAlgorithm from VTK 5.4 and
>>>> together
>>>> with vtkTemporalDataSet cannot be used anymore in 6.2. What should I do
>>>> with
>>>> those functions, how could I change them?
>>>>
>>>> Thanks alot
>>>>
>>>> Yan
>>>>
>>>> _______________________________________________
>>>> 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
>>>>
>>>> Search the list archives at: http://markmail.org/search/?q=vtkusers
>>>>
>>>> Follow this link to subscribe/unsubscribe:
>>>> http://public.kitware.com/mailman/listinfo/vtkusers
>>>>
>>>
>>>
>>>
>>
>
>
> --
> mit freundlicher Grüße
> Yan Liu
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://public.kitware.com/pipermail/vtkusers/attachments/20150915/35ca7f4b/attachment.html>


More information about the vtkusers mailing list