36 #include <QtConcurrent> 37 #include <QDesktopWidget> 38 #include <QApplication> 40 #include "boost/bind.hpp" 42 #include <QVBoxLayout> 46 #include "vtkRenderer.h" 47 #include "vtkWindowToImageFilter.h" 48 #include "vtkRenderWindow.h" 49 #include "vtkPNGWriter.h" 50 #include "vtkUnsignedCharArray.h" 53 #include "vtkImageImport.h" 67 std::vector<ViewPtr> views = mWidget->
getViews();
68 Eigen::Array3i target_size(mWidget->width(), mWidget->height(), 1);
71 for (
unsigned i=0; i<views.size(); ++i)
74 QPoint vtkpos = this->getVtkPositionOfView(views[i]);
75 this->drawImageAtPos(target, vtkImage, vtkpos);
81 QPoint ViewCollectionImageWriter::getVtkPositionOfView(
ViewPtr view)
85 Eigen::Array2i size_view(view->getRenderer()->GetSize());
87 QPoint qpos_ll = qpos_ul + QPoint(0, size_view[1]-1);
89 QPoint vtkpos_ll = this->qt2vtk(qpos_ll);
94 QPoint ViewCollectionImageWriter::qt2vtk(QPoint qpos)
96 int H = mWidget->height();
97 QPoint vtkpos(qpos.x(), H-1-qpos.y());
104 unsigned char* src =
reinterpret_cast<unsigned char*
>(image->GetScalarPointer());
105 unsigned char* dst =
reinterpret_cast<unsigned char*
>(target->GetScalarPointer());
106 Eigen::Array3i dim_src(image->GetDimensions());
108 CX_ASSERT(target->GetNumberOfScalarComponents()==depth);
109 CX_ASSERT(image->GetNumberOfScalarComponents()==depth);
111 for (
int y=0; y<dim_src[1]; ++y)
113 unsigned char* src =
reinterpret_cast<unsigned char*
>(image->GetScalarPointer(0,y,0));
114 unsigned char* dst =
reinterpret_cast<unsigned char*
>(target->GetScalarPointer(pos.x(),pos.y()+y,0));
115 memcpy(dst, src, dim_src[0]*depth);
140 Eigen::Array4d vp(renderer->GetViewport());
142 Eigen::Array2i origin(renderer->GetOrigin());
143 Eigen::Array2i size(renderer->GetSize());
144 Eigen::Array<int,6,1> extent;
146 extent[1] = size[0]-1;
148 extent[3] = size[1]-1;
151 int frontBuffer =
false;
153 unsigned char *pixels;
157 renderWindow->MakeCurrent();
159 pixels = renderWindow->GetPixelData(origin[0], origin[1], origin[0]+size[0]-1, origin[1]+size[1]-1, frontBuffer);
165 vtkImageImportPtr
import = vtkImageImportPtr::New();
166 import->SetDataScalarTypeToUnsignedChar();
167 import->SetNumberOfScalarComponents(3);
168 import->SetDataExtent(extent.data());
169 import->SetWholeExtent(extent.data());
170 bool takeOwnership =
true;
171 import->SetImportVoidPointer(pixels, !takeOwnership);
173 return import->GetOutput();
179 CX_ASSERT(input->GetNumberOfScalarComponents()==3);
180 CX_ASSERT(input->GetScalarType() == VTK_UNSIGNED_CHAR);
182 unsigned char* ptr =
reinterpret_cast<unsigned char*
>(input->GetScalarPointer());
183 Eigen::Array3i dim(input->GetDimensions());
186 QImage retval(ptr, dim[0], dim[1], dim[0]*3, QImage::Format_RGB888);
188 return retval.copy().mirrored(
false,
true);
#define CX_ASSERT(statement)
ViewCollectionImageWriter(ViewCollectionWidget *widget)
vtkSmartPointer< class vtkRenderWindow > vtkRenderWindowPtr
boost::shared_ptr< class View > ViewPtr
static QImage vtkImageData2QImage(vtkImageDataPtr input)
vtkSmartPointer< class vtkRenderer > vtkRendererPtr
vtkImageDataPtr generateVtkImageData(Eigen::Array3i dim, Vector3D spacing, const unsigned char initValue, int components)
Eigen::Vector3d Vector3D
Vector3D is a representation of a point or vector in 3D.
vtkSmartPointer< class vtkImageImport > vtkImageImportPtr
Namespace for all CustusX production code.