46 #include <vtkImageData.h> 47 #include <vtkInformation.h> 48 #include <vtkInformationVector.h> 49 #include <vtkStreamingDemandDrivenPipeline.h> 50 #include <vtkObjectFactory.h> 58 this->SetNumberOfInputPorts(0);
64 vtkInformation* outInfo = outputVector->GetInformationObject(0);
66 outInfo->Set(vtkStreamingDemandDrivenPipeline::WHOLE_EXTENT(), this->ImageData->GetExtent(), 6);
67 outInfo->Set(vtkDataObject::SPACING(), 1.0, 1.0, 1.0);
68 outInfo->Set(vtkDataObject::ORIGIN(), 0.0, 0.0, 0.0);
70 vtkDataObject::SetPointDataActiveScalarInfo(outInfo, this->ImageData->GetScalarType(), this->ImageData->GetNumberOfScalarComponents());
76 vtkInformation *outInfo = outputVector->GetInformationObject(0);
78 vtkImageData *output = vtkImageData::SafeDownCast(outInfo->Get(vtkDataObject::DATA_OBJECT()) );
79 output->ShallowCopy(this->ImageData);
85 CV_Assert(_image.depth() == CV_8U && (_image.channels() == 1 || _image.channels() == 3 || _image.channels() == 4));
87 cv::Mat image = _image.getMat();
89 this->ImageData->SetDimensions(image.cols, image.rows, 1);
90 #if VTK_MAJOR_VERSION <= 5 91 this->ImageData->SetNumberOfScalarComponents(image.channels());
92 this->ImageData->SetScalarTypeToUnsignedChar();
93 this->ImageData->AllocateScalars();
95 this->ImageData->AllocateScalars(VTK_UNSIGNED_CHAR, image.channels());
98 switch(image.channels())
100 case 1: copyGrayImage(image, this->ImageData);
break;
101 case 3: copyRGBImage (image, this->ImageData);
break;
102 case 4: copyRGBAImage(image, this->ImageData);
break;
104 this->ImageData->Modified();
109 unsigned char* dptr =
reinterpret_cast<unsigned char*
>(output->GetScalarPointer());
110 size_t elem_step = output->GetIncrements()[1]/
sizeof(
unsigned char);
112 for (
int y = 0; y < source.rows; ++y)
114 unsigned char* drow = dptr + elem_step * y;
115 const unsigned char *srow = source.ptr<
unsigned char>(source.rows-(y+1));
116 for (
int x = 0; x < source.cols; ++x)
123 cv::Vec3b* dptr =
reinterpret_cast<cv::Vec3b*
>(output->GetScalarPointer());
124 size_t elem_step = output->GetIncrements()[1]/
sizeof(cv::Vec3b);
126 for (
int y = 0; y < source.rows; ++y)
128 cv::Vec3b* drow = dptr + elem_step * y;
129 const unsigned char *srow = source.ptr<
unsigned char>(source.rows - (y + 1));
130 for (
int x = 0; x < source.cols; ++x, srow += source.channels())
131 drow[x] = cv::Vec3b(srow[2], srow[1], srow[0]);
137 cv::Vec4b* dptr =
reinterpret_cast<cv::Vec4b*
>(output->GetScalarPointer());
138 size_t elem_step = output->GetIncrements()[1]/
sizeof(cv::Vec4b);
140 for (
int y = 0; y < source.rows; ++y)
142 cv::Vec4b* drow = dptr + elem_step * y;
143 const unsigned char *srow = source.ptr<
unsigned char>(source.rows - (y + 1));
144 for (
int x = 0; x < source.cols; ++x, srow += source.channels())
145 drow[x] = cv::Vec4b(srow[2], srow[1], srow[0], srow[3]);
vtkStandardNewMacro(CloudViewerCellPicker)
int RequestInformation(vtkInformation *, vtkInformationVector **, vtkInformationVector *)
void SetImage(cv::InputArray image)
int RequestData(vtkInformation *, vtkInformationVector **, vtkInformationVector *)
static void copyRGBAImage(const cv::Mat &source, vtkSmartPointer< vtkImageData > output)
static void copyRGBImage(const cv::Mat &source, vtkSmartPointer< vtkImageData > output)
static void copyGrayImage(const cv::Mat &source, vtkSmartPointer< vtkImageData > output)