On Sat, Feb 6, 2010 at 11:07 AM, David Doria <span dir="ltr"><<a href="mailto:daviddoria%2Bvtk@gmail.com">daviddoria+vtk@gmail.com</a>></span> wrote:<br><div class="gmail_quote"><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex;">
Is there any reason we can't have a templated single input, single output filter?<div><br></div><div>Currently, it looks like the preferred method is to derive from the class *Algorithm of the intended output type and change the input type in the FillInputPortInformation function.</div>


<div><br></div><div>Lets take an example of a filter which takes as input a vtkPointSet and produces a vtkPolyData:</div><div><br></div><div><u><b>Current method:</b></u></div><div><br></div><div>class MyFilter : vtkPolyDataAlgorithm</div>


<div><br></div><div><div>int MyFilter::FillInputPortInformation( int port, vtkInformation* info )</div><div>{</div><div>  if (port == 0)</div><div>    {</div><div>    info->Set( vtkAlgorithm::INPUT_REQUIRED_DATA_TYPE(), "vtkPointSet" );</div>


<div>    return 1;</div><div>    }</div><div><br></div><div>  return 0;</div><div>}</div><div><br></div><div><b><u>Proposed method:</u></b></div><div><b><u><br></u></b></div><div>class MyFilter : vtkFilter<vtkPointSet, vtkPolyData></div>


<div><b><u><br></u></b></div><div><b><u><br></u></b></div><div>Thoughts? I may be over my head in template programming and pipeline stuff, but maybe the experts can discuss/comment?</div><div><br></div></div><div>Thanks,<br>

<br>David<br>

</div>
<br></blockquote><div><br></div><div>As others have commented, please avoid using templates. It complicates the wrapping mechanisms used to build python, java and tcl wrappers for VTK. When wrapped, only concrete instantiations of templates may be wrapped, and since there is usually no template mechanism in the target languages, the only way to do it is to invent a mangled name for use in the target language. It gets pretty ugly pretty fast.</div>
<div><br></div><div>The official policy should be:</div><div>-- no C++ template parameters allowed in:</div><div>  -- class declarations of public classes that derive from vtkObject</div><div>  -- public method signatures of those same classes</div>
<div><br></div><div>Of course, you may use templates internal to a *.cxx file as long as they do not affect the API.</div><div><br></div><div>I don't know if this policy is expressed anywhere, (anybody from the ARB listening?) and there is a single violation of it (that I know of) that we certainly don't want to propagate to other uses.</div>
<div><br></div><div><br></div><div>Thanks,</div><div>David C.</div><div><br></div><div><br></div><div>P.S. - The subclasses of vtkDataArrayTemplate and the trickery we use with #define vtkDataArray are the single violation I speak of. Look it up, it's not pretty.</div>
<div><br></div><div>For example, from vtkLongArray.h:</div><div><p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 14.0px Monaco; color: #008400">// Fake the superclass for the wrappers.</p>
<p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 14.0px Monaco; color: #78492a">#define vtkDataArray vtkDataArrayTemplate<long></p>
<p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 14.0px Monaco"><span style="color: #ba2da2">class</span> VTK_COMMON_EXPORT vtkLongArray : <span style="color: #ba2da2">public</span> vtkDataArray</p>
<p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 14.0px Monaco; color: #78492a">#undef vtkDataArray</p><div><font class="Apple-style-span" color="#78492A" face="Monaco" size="4"><span class="Apple-style-span" style="font-size: 14px;"><br>
</span></font></div></div></div>