VTK/Marks/Design

From KitwarePublic
< VTK‎ | Marks
Jump to navigationJump to search

The following are some discussions about the design of the VTK/Marks classes.

Fleshing Out the vtkMark API

The fundamental type would be vtkMark, the superclass of all mark types. Its interface would define how programmers would work with all marks in VTK. The following sections enumerate some possible use cases with code snippets showing what functionality the feature would allow.

Possible Supported Parameter Types

Description Example Code
Basic types (double, int, string, vtkVariant)
vtkDotMark* m = vtkDotMark::New();
m->SetParameter("size", 10);
Data object
vtkDirectedGraph* g = vtkDirectedGraph::New();
//...
vtkDotMark* m = vtkDotMark::New();
m->SetParameter("data", g);
Pipeline output port
vtkRandomGraphSource* s = vtkRandomGraphSource::New();
//...
vtkDotMark* m = vtkDotMark::New();
m->SetParameter("data", s->GetOutputPort());
vtkArray
vtkDenseArray<double>* a = vtkDenseArray<double>::New();
//...
vtkDotMark* m = vtkDotMark::New();
m->SetParameter("size", a);
vtkAbstractArray
vtkDoubleArray* a = vtkDoubleArray::New();
//...
vtkDotMark* m = vtkDotMark::New();
m->SetParameter("size", a);
Data object + field type + array name
vtkTable* t = vtkTable::New();
//...
vtkDotMark* m = vtkDotMark::New();
m->SetParameter("size", t, vtkDataObject::ROW, "columnName");
Data object + field type + array name + component index
vtkTable* t = vtkTable::New();
vtkDoubleArray* loc = vtkDoubleArray::New();
loc->SetNumberOfComponents(2);
//...
vtkDotMark* m = vtkDotMark::New();
m->SetParameter("left", t, vtkDataObject::ROW, "location", 0);
m->SetParameter("bottom", t, vtkDataObject::ROW, "location", 1);
Function pointer
double MySize(vtkMark* m, int i) { return 10*i; }
//...
vtkDotMark* m = vtkDotMark::New();
m->SetParameter("size", &MySize);
Functor (i.e. struct type with operator()) - requires SetParameter to be templated.
struct MySize {
  double operator()(vtkMark* m, int i) { return 10*i; }
}
//...
vtkDotMark* m = vtkDotMark::New();
m->SetParameter("size", MySize());
Lambda function (boost::lambda)
Parameter strategies
class vtkDoubleParameter {
  virtual double Get(vtkMark* m, int i) = 0;
}

class MySize : public vtkDoubleParameter {
protected:
  double Get(vtkMark* m, int i) { return 10*i; }
}
//...
vtkDotMark* m = vtkDotMark::New();
m->SetParameter("size", MySize());
Override virtual methods in mark
class vtkDotMark : public vtkMark {
protected:
  virtual double GetSize(int i) { return 10; }
}

class MyMark : public vtkDotMark {
protected:
  double GetSize(int i) { return 10*i; }
}
//...
MyMark* m = MyMark::New();
Inherit from parent mark
vtkDotMark* parent = vtkDotMark::New();
parent->SetParameter("size", 10);
vtkDotMark* child = vtkDotMark::New();
parent->Add(child); // Child has size 10


Possible Parameter Storage and Access

Named member variables

class vtkDotMark {
public:
  ParamType GetSize() { return this->Size; }
  void SetSize(ParamType p) { this->Size = p; }
private:
  ParamType Size;
}

Named member variables with import/export to name/value map

class vtkMark {
public:
  ParamType GetParameter(string key)
  { this->ExportSettings()->GetParameter(key); }
  void SetParameter(string key, ParamType p)
  { this->ImportSettings(this->ExportSettings()->SetParameter(key, p)); }
  virtual void ImportSettings(vtkSettings* s) { }
  virtual vtkSettings* ExportSettings() { return vtkSettings::New(); }
}

class vtkDotMark {
public:
  ParamType GetSize() { return this->Size; }
  void SetSize(ParamType p) { this->Size = p; }
  virtual vtkSettings* ExportSettings()
  { return this->Parent->ExportSettings()->SetParameter("size", this->Size); }
  virutal void ImportSettings(vtkSettings* s)
  { this->Size = s->GetParameter("size"); }
private:
  ParamType Size;
}

Generic name/value map

class vtkMark {
public:
  ParamType GetParameter(string key)
  { return this->Parameters[key].Valid ? this->Parameters[key] : this->Parent->GetParameter(key); }
  void SetParameter(string key, ParamType p)
  { this->Parameters[key] = p; }
private:
  map<string, ParamType> Parameters;
}

Generic name/value map with setter/getter syntactic sugar for discoverability

class vtkDotMark : public vtkMark {
public:
  ParamType GetSize() { return this->GetParameter("size"); }
  void SetSize(ParamType p) { this->SetParameter("size", p); }
}

vtkInformation/value map

The idea here is that valid parameter names/types/bounds are queryable at runtime, instead of in an opaque map.

class vtkMark {
public:
  // Keys to describe parameters
  static vtkInformationIntegerKey* PARAMETER_TYPE();
  static vtkInformationStringKey* PARAMETER_NAME();
  static vtkInformationIntegerKey* PARAMETER_NUMBER_OF_COMPONENTS();
  static vtkInformationIntegerVectorKey* PARAMETER_INTEGER_BOUNDS();
  static vtkInformationDoubleVectorKey* PARAMETER_REAL_BOUNDS();

  int GetNumberOfParameters() { return this->ParameterInfo->size(); }
  vtkInformation* GetParameterInfo(int i) { return this->ParameterInfo[i]; }
  int GetParameterHandle(const char* name)
  { /* search ParameterInfo for name, return index */ }
  void SetParameter(int handle, ParamType p)
  { this->ParameterValues[handle] = p; }

protected:
  virtual void SetupParameters() = 0;
  vector<vtkInformation*> ParameterInfo;
  vector<ParamType> ParameterValues;
}

class vtkDotMark : public vtkMark {
protected:
  void SetupParameters()
  {
    vtkInformation* sizeInfo = vtkInformation::New();
    double sizeBounds[2] = { 0., VTK_DOUBLE_MAX };
    sizeInfo->Set( vtkPointMark::PARAMETER_NAME(), "size" );
    sizeInfo->Set( vtkPointMark::PARAMETER_TYPE(), VTK_DOUBLE );
    sizeInfo->Set( vtkPointMark::PARAMETER_NUMBER_OF_COMPONENTS(), 1 );
    sizeInfo->Set( vtkPointMark::PARAMETER_REAL_BOUNDS(), sizeBounds, 2 );
    this->ParameterInfo.push_back(sizeInfo);
    this->ParameterValues.push_back(10);
  }
}

Possible Other Features

  • Declarative API
  • Iterator support