title: C++ - Defining class template (header/source file)
body: <p>I want to create a processor in voreen (like this one <a href="http://voreen.uni-muenster.de/doc/4.2/curvatureanisotropicdiffusionimagefilter_8cpp_source.html" rel="nofollow">.cpp</a> | <a href="http://voreen.uni-muenster.de/doc/4.2/curvatureanisotropicdiffusionimagefilter_8h_source.html" rel="nofollow">.h</a>) porting this OTB-Application:</p>
  
  <p><a href="http://hg.orfeo-toolbox.org/OTB/file/ca4366bb972e/Applications/Segmentation/otbSegmentation.cxx" rel="nofollow">http://hg.orfeo-toolbox.org/OTB/file/ca4366bb972e/Applications/Segmentation/otbSegmentation.cxx</a></p>
  
  <p>I have coded almost all the parameters into properties, etc but..</p>
  
  <p>If you look at like <a href="http://hg.orfeo-toolbox.org/OTB/file/ca4366bb972e/Applications/Segmentation/otbSegmentation.cxx#l376" rel="nofollow">376</a>, you'll see a class template of FloatVectorImageType::SizeType, a typedef type. </p>
  
  <p>Im not familiar with c++ templates so my first question was where should I put this template's implementation, in the .cpp or .h file of the processor? Taking a brief look at c++ tutorials and other processor examples like the <a href="http://voreen.uni-muenster.de/doc/4.2/curvatureanisotropicdiffusionimagefilter_8cpp_source.html" rel="nofollow">one above</a>, I figure out I have to declare the template in header and define it in the .cpp.</p>
  
  <p>The problem is that the compiler doesnt allow me to define a template class of a typedef type inside the .cpp. The typedef isnt recognised..</p>
  
  <p>So, can someone point me to the right direction here?</p>
  
  <p><em><strong>segmentationprocessor.h</em></strong></p>
  
  <pre><code>#ifndef OTBSEGMENTATIONAPPLICATION_H
  #define OTBSEGMENTATIONAPPLICATION_H
  
  #include "otbVectorImage.h"
  #include "modules/otb/ports/otbimageport.h"
  #include "modules/otb/ports/otbvectorimageport.h"
  #include "voreen/core/properties/boolproperty.h"
  
  //..more includes here
  
  namespace voreen {
  
  class OTBSegmentationApplication : public OTBImageFilterProcessor
  {
  public:
      OTBSegmentationApplication();
  
      virtual ~OTBSegmentationApplication();
  
      virtual Processor* create() const;
  
      virtual std::string getCategory() const { return "Applications"; }
      virtual std::string getClassName() const { return "Segmentation Application"; }
      virtual CodeState getCodeState() const { return CODE_STATE_EXPERIMENTAL;}//STABLE, TESTING, EXPERIMENTAL
  
      virtual std::string getProcessorInfo() const;
  
      /** Images typedefs */
      typedef otb::VectorImage&lt;double, 2&gt; VectorImageType;
      typedef ImageType               LabelImageType;
      typedef ImageType               MaskImageType;
  
      typedef VectorImageType::SizeType size;
  
      // Segmentation filters typedefs
      // Edison mean-shift
      typedef otb::MeanShiftVectorImageFilter&lt;VectorImageType,VectorImageType,LabelImageType&gt; EdisonSegmentationFilterType;
      EdisonSegmentationFilterType::Pointer edisonFilter;
  
      // Home made mean-shift
      typedef otb::MeanShiftSegmentationFilter&lt;VectorImageType, LabelImageType, VectorImageType&gt; MeanShiftSegmentationFilterType;
      MeanShiftSegmentationFilterType::Pointer meanshiftFilter;
  
      // Simple connected components
      typedef otb::Functor::ConnectedComponentMuParserFunctor&lt;VectorImageType::PixelType&gt; FunctorType;
  
      typedef itk::ConnectedComponentFunctorImageFilter &lt;VectorImageType, LabelImageType, FunctorType, MaskImageType&gt; ConnectedComponentSegmentationFilterType;
      ConnectedComponentSegmentationFilterType::Pointer ccFilter;
  
      typedef itk::ScalarConnectedComponentImageFilter&lt;LabelImageType, LabelImageType&gt; LabeledConnectedComponentSegmentationFilterType;
      LabeledConnectedComponentSegmentationFilterType::Pointer labeledCCFilter;
  
      //..more typedefs here
  
  protected:
      virtual void setDescriptions() {
          setDescription("Performs segmentation of an image, and output either a raster or a vector file. In vector mode, large input datasets are supported.");
      }
      void process();
      virtual void initialize() throw (tgt::Exception);
      virtual void deinitialize() throw (tgt::Exception);
  
      /** TEMPLATE DECLARATION (?) */
  
      template&lt;class TInputImage, class TSegmentationFilter&gt;
      VectorImageType::SizeType GenericApplySegmentation(otb::StreamingImageToOGRLayerSegmentationFilter
                                                         &lt;TInputImage, TSegmentationFilter&gt; * streamingVectorizedFilter, TInputImage * inputImage,
                                                         const otb::ogr::Layer&amp; layer, const unsigned int outputNb);
      virtual void updateFilterSelection();
      virtual void updateModeSelection();
  
  private:
  
      OTBVectorImagePort inPort_;
      StringOptionProperty filter_; ///&lt; Select segmentation algorithm
      OTBVectorImagePort vectorOutPort_;
      OTBImagePort vectorMaskInPort_;
      OTBImagePort outPort_;
  
      //..more property definitions here
  
      static const std::string loggerCat_; ///&lt; Category used in logging
  };
  
  } // namespace
  
  #endif // OTBSEGMENTATIONAPPLICATION_H
  </code></pre>
  
  <p><em><strong>segmentationprocessor.cpp</em></strong></p>
  
  <pre><code>#include "segmentationprocessor.h"
  #include "voreen/core/voreenapplication.h"
  
  namespace voreen {
  
  const std::string OTBSegmentationApplication::loggerCat_("voreen.OTBSegmentationApplication");
  
  OTBSegmentationApplication::OTBSegmentationApplication()
      :OTBImageFilterProcessor(),
        inPort_(Port::INPORT, "IN Multiband Image", 0),
        vectorOutPort_(Port::OUTPORT, "OUT Multiband Image", 0),
        vectorMaskInPort_(Port::INPORT, "IN Mask Image", 0),
        outPort_(Port::OUTPORT, "OUT OTB Image", 0),
  
        filter_("selectFilter", "Segmentation algorithm"),
  
        //.. more properties code here
  
  {
      addPort(inPort_);
      addPort(vectorOutPort_);
      addPort(vectorMaskInPort_);
      addPort(outPort_);
  
      addProperty(filter_);
  
      //.. adding the rest of properties here
  
      edisonFilter = EdisonSegmentationFilterType::New();
      meanshiftFilter = MeanShiftSegmentationFilterType::New();
      ccFilter = ConnectedComponentSegmentationFilterType::New();
  
      //..instantiating more filters needed in implementation here
  
  }
  
  Processor* OTBSegmentationApplication::create() const {
      return new OTBSegmentationApplication();
  }
  
  OTBSegmentationApplication::~OTBSegmentationApplication() {
  
  }
  
  void OTBSegmentationApplication::initialize() throw (tgt::Exception) {
      Processor::initialize();
  }
  
  void OTBSegmentationApplication::deinitialize() throw (tgt::Exception) {
      Processor::deinitialize();
  }
  
  std::string OTBSegmentationApplication::getProcessorInfo() const {
      return "Segmentation Application";
  }
  
  void OTBSegmentationApplication::updateFilterSelection() {
      //code for visual updates on properties here
  }
  
  void OTBSegmentationApplication::updateModeSelection() {
      //code for visual updates on properties here
  }
  
      //TEMPLATE IMPLEMENTATION HERE (?)
  template&lt;class TInputImage, class TSegmentationFilter&gt;
  OTBSegmentationApplication::VectorImageType::SizeType OTBSegmentationApplication::GenericApplySegmentation(otb::StreamingImageToOGRLayerSegmentationFilter&lt;TInputImage,
                               TSegmentationFilter&gt; * streamingVectorizedFilter, TInputImage * inputImage, const otb::ogr::Layer&amp; layer, const unsigned int outputNb)
      {
          typedef  TSegmentationFilter SegmentationFilterType;
          typedef  typename SegmentationFilterType::Pointer SegmentationFilterPointerType;
          typedef otb::StreamingImageToOGRLayerSegmentationFilter&lt;TInputImage,SegmentationFilterType&gt; StreamingVectorizedSegmentationOGRType;
  
      //..the rest of template code here
  }
  
  
  void OTBSegmentationApplication::process() {
  
      try
      {
          //PROCESSOR IMPLEMENTATION GOES HERE
          LINFO("Segmentation Application Connected");
      }
      catch (int e)
      {
          LERROR("Error in Segmentation Applicationn");
          return;
      }
  }
  
  }   // namespace
  </code></pre>
  
  <blockquote>
    <p><strong>error: ‘VectorImageType’ does not name a type (fixed)</strong></p>
  </blockquote>