46 #include <vtkImageData.h>
47 #include <vtkInformation.h>
48 #include <vtkInformationVector.h>
49 #include <vtkStreamingDemandDrivenPipeline.h>
50 #include <vtkObjectFactory.h>
51 #include <vtkVersionMacros.h>
59 this->SetNumberOfInputPorts(0);
65 vtkInformation* outInfo = outputVector->GetInformationObject(0);
67 outInfo->Set(vtkStreamingDemandDrivenPipeline::WHOLE_EXTENT(), this->ImageData->GetExtent(), 6);
68 outInfo->Set(vtkDataObject::SPACING(), 1.0, 1.0, 1.0);
69 outInfo->Set(vtkDataObject::ORIGIN(), 0.0, 0.0, 0.0);
71 vtkDataObject::SetPointDataActiveScalarInfo(outInfo, this->ImageData->GetScalarType(),
this->ImageData->GetNumberOfScalarComponents());
77 vtkInformation *outInfo = outputVector->GetInformationObject(0);
79 vtkImageData *output = vtkImageData::SafeDownCast(outInfo->Get(vtkDataObject::DATA_OBJECT()) );
80 output->ShallowCopy(this->ImageData);
86 CV_Assert(_image.depth() == CV_8U && (_image.channels() == 1 || _image.channels() == 3 || _image.channels() == 4));
88 cv::Mat image = _image.getMat();
90 this->ImageData->SetDimensions(image.cols, image.rows, 1);
91 #if VTK_MAJOR_VERSION <= 5
92 this->ImageData->SetNumberOfScalarComponents(image.channels());
93 this->ImageData->SetScalarTypeToUnsignedChar();
94 this->ImageData->AllocateScalars();
96 this->ImageData->AllocateScalars(VTK_UNSIGNED_CHAR, image.channels());
99 switch(image.channels())
101 case 1: copyGrayImage(image, this->ImageData);
break;
102 case 3: copyRGBImage (image, this->ImageData);
break;
103 case 4: copyRGBAImage(image, this->ImageData);
break;
105 this->ImageData->Modified();
110 unsigned char* dptr =
reinterpret_cast<unsigned char*
>(output->GetScalarPointer());
111 size_t elem_step = output->GetIncrements()[1]/
sizeof(
unsigned char);
115 unsigned char* drow = dptr + elem_step *
y;
116 const unsigned char *srow =
source.ptr<
unsigned char>(
source.rows-(
y+1));
124 cv::Vec3b* dptr =
reinterpret_cast<cv::Vec3b*
>(output->GetScalarPointer());
125 size_t elem_step = output->GetIncrements()[1]/
sizeof(cv::Vec3b);
129 cv::Vec3b* drow = dptr + elem_step *
y;
130 const unsigned char *srow =
source.ptr<
unsigned char>(
source.rows - (
y + 1));
132 drow[
x] = cv::Vec3b(srow[2], srow[1], srow[0]);
138 cv::Vec4b* dptr =
reinterpret_cast<cv::Vec4b*
>(output->GetScalarPointer());
139 size_t elem_step = output->GetIncrements()[1]/
sizeof(cv::Vec4b);
143 cv::Vec4b* drow = dptr + elem_step *
y;
144 const unsigned char *srow =
source.ptr<
unsigned char>(
source.rows - (
y + 1));
146 drow[
x] = cv::Vec4b(srow[2], srow[1], srow[0], srow[3]);