15 #include <QtConcurrent> 16 #include <QDesktopWidget> 17 #include <QApplication> 19 #include "boost/bind.hpp" 21 #include <QVBoxLayout> 25 #include "vtkRenderer.h" 26 #include "vtkWindowToImageFilter.h" 27 #include "vtkRenderWindow.h" 28 #include "vtkPNGWriter.h" 29 #include "vtkUnsignedCharArray.h" 32 #include "vtkImageImport.h" 46 std::vector<ViewPtr> views = mWidget->
getViews();
47 Eigen::Array3i target_size(mWidget->width(), mWidget->height(), 1);
50 for (
unsigned i=0; i<views.size(); ++i)
53 QPoint vtkpos = this->getVtkPositionOfView(views[i]);
54 this->drawImageAtPos(target, vtkImage, vtkpos);
60 QPoint ViewCollectionImageWriter::getVtkPositionOfView(
ViewPtr view)
64 Eigen::Array2i size_view(view->getRenderer()->GetSize());
66 QPoint qpos_ll = qpos_ul + QPoint(0, size_view[1]-1);
68 QPoint vtkpos_ll = this->qt2vtk(qpos_ll);
73 QPoint ViewCollectionImageWriter::qt2vtk(QPoint qpos)
75 int H = mWidget->height();
76 QPoint vtkpos(qpos.x(), H-1-qpos.y());
83 unsigned char* src =
reinterpret_cast<unsigned char*
>(image->GetScalarPointer());
84 unsigned char* dst =
reinterpret_cast<unsigned char*
>(target->GetScalarPointer());
85 Eigen::Array3i dim_src(image->GetDimensions());
87 CX_ASSERT(target->GetNumberOfScalarComponents()==depth);
88 CX_ASSERT(image->GetNumberOfScalarComponents()==depth);
90 for (
int y=0; y<dim_src[1]; ++y)
92 unsigned char* src =
reinterpret_cast<unsigned char*
>(image->GetScalarPointer(0,y,0));
93 unsigned char* dst =
reinterpret_cast<unsigned char*
>(target->GetScalarPointer(pos.x(),pos.y()+y,0));
94 memcpy(dst, src, dim_src[0]*depth);
119 Eigen::Array4d vp(renderer->GetViewport());
121 Eigen::Array2i origin(renderer->GetOrigin());
122 Eigen::Array2i size(renderer->GetSize());
123 Eigen::Array<int,6,1> extent;
125 extent[1] = size[0]-1;
127 extent[3] = size[1]-1;
130 int frontBuffer =
false;
132 unsigned char *pixels;
136 renderWindow->MakeCurrent();
138 pixels = renderWindow->GetPixelData(origin[0], origin[1], origin[0]+size[0]-1, origin[1]+size[1]-1, frontBuffer);
144 vtkImageImportPtr
import = vtkImageImportPtr::New();
145 import->SetDataScalarTypeToUnsignedChar();
146 import->SetNumberOfScalarComponents(3);
147 import->SetDataExtent(extent.data());
148 import->SetWholeExtent(extent.data());
149 bool takeOwnership =
true;
150 import->SetImportVoidPointer(pixels, !takeOwnership);
152 return import->GetOutput();
158 CX_ASSERT(input->GetNumberOfScalarComponents()==3);
159 CX_ASSERT(input->GetScalarType() == VTK_UNSIGNED_CHAR);
161 unsigned char* ptr =
reinterpret_cast<unsigned char*
>(input->GetScalarPointer());
162 Eigen::Array3i dim(input->GetDimensions());
165 QImage retval(ptr, dim[0], dim[1], dim[0]*3, QImage::Format_RGB888);
167 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.