【发布时间】:2013-11-12 10:09:38
【问题描述】:
我想在 voreen 中创建一个处理器(就像这个 .cpp | .h)移植这个 OTB 应用程序:
http://hg.orfeo-toolbox.org/OTB/file/ca4366bb972e/Applications/Segmentation/otbSegmentation.cxx
我已经将几乎所有的参数都编码成属性等,但是..
如果您查看376,您将看到 FloatVectorImageType::SizeType 的类模板,这是一个 typedef 类型。
我不熟悉 c++ 模板,所以我的第一个问题是我应该把这个模板的实现放在哪里,在处理器的 .cpp 或 .h 文件中?简要看一下 c++ 教程和其他处理器示例,如 one above,我发现我必须在 header 中声明模板并在 .cpp 中定义它。
问题是编译器不允许我在 .cpp 中定义 typedef 类型的模板类。 typedef 无法识别..
那么,有人可以在这里指出正确的方向吗?
segmentationprocessor.h
#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<double, 2> VectorImageType;
typedef ImageType LabelImageType;
typedef ImageType MaskImageType;
typedef VectorImageType::SizeType size;
// Segmentation filters typedefs
// Edison mean-shift
typedef otb::MeanShiftVectorImageFilter<VectorImageType,VectorImageType,LabelImageType> EdisonSegmentationFilterType;
EdisonSegmentationFilterType::Pointer edisonFilter;
// Home made mean-shift
typedef otb::MeanShiftSegmentationFilter<VectorImageType, LabelImageType, VectorImageType> MeanShiftSegmentationFilterType;
MeanShiftSegmentationFilterType::Pointer meanshiftFilter;
// Simple connected components
typedef otb::Functor::ConnectedComponentMuParserFunctor<VectorImageType::PixelType> FunctorType;
typedef itk::ConnectedComponentFunctorImageFilter <VectorImageType, LabelImageType, FunctorType, MaskImageType> ConnectedComponentSegmentationFilterType;
ConnectedComponentSegmentationFilterType::Pointer ccFilter;
typedef itk::ScalarConnectedComponentImageFilter<LabelImageType, LabelImageType> 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<class TInputImage, class TSegmentationFilter>
VectorImageType::SizeType GenericApplySegmentation(otb::StreamingImageToOGRLayerSegmentationFilter
<TInputImage, TSegmentationFilter> * streamingVectorizedFilter, TInputImage * inputImage,
const otb::ogr::Layer& layer, const unsigned int outputNb);
virtual void updateFilterSelection();
virtual void updateModeSelection();
private:
OTBVectorImagePort inPort_;
StringOptionProperty filter_; ///< Select segmentation algorithm
OTBVectorImagePort vectorOutPort_;
OTBImagePort vectorMaskInPort_;
OTBImagePort outPort_;
//..more property definitions here
static const std::string loggerCat_; ///< Category used in logging
};
} // namespace
#endif // OTBSEGMENTATIONAPPLICATION_H
segmentationprocessor.cpp
#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<class TInputImage, class TSegmentationFilter>
OTBSegmentationApplication::VectorImageType::SizeType OTBSegmentationApplication::GenericApplySegmentation(otb::StreamingImageToOGRLayerSegmentationFilter<TInputImage,
TSegmentationFilter> * streamingVectorizedFilter, TInputImage * inputImage, const otb::ogr::Layer& layer, const unsigned int outputNb)
{
typedef TSegmentationFilter SegmentationFilterType;
typedef typename SegmentationFilterType::Pointer SegmentationFilterPointerType;
typedef otb::StreamingImageToOGRLayerSegmentationFilter<TInputImage,SegmentationFilterType> 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
错误:“VectorImageType”没有命名类型(固定)
【问题讨论】:
-
见Why can templates only be implemented in the header file?;请将任何相关代码复制到问题中。这样可以更轻松地理解您的问题并防止出现链接断开的问题(将来)。
-
这是我检查的第一个教程,谢谢。我可以将代码复制到问题中,但恐怕它有点大..
-
只有 相关 部分;) 或者更好的 a short, but complete example 重现或说明您的问题
-
CurvatureAnisotropicDiffusionImageFilterITK::curvatureAnisotropicDiffusionImageFilterITK的情况当然很奇怪。它是受保护的,但在 .cpp 中定义了这意味着,任何派生类只能使用在 .cpp 中生成的实例化,这些实例化用于float和double类型——这些是隐式 实例化。这似乎不是故意的。 -
VectorImageType::SizeType OTBSegmentationApplication::GenericApplySegmentation试试OTBSegmentationApplication::VectorImageType::SizeType OTBSegmentationApplication::GenericApplySegmentation我会写一个涵盖其他问题的答案,但这需要一些时间。
标签: c++ header-files porting class-template