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)
75 QPoint vtkpos = this->getVtkPositionOfView(views[i]);
76 this->drawImageAtPos(target, vtkImage, vtkpos);
82 QPoint ViewCollectionImageWriter::getVtkPositionOfView(
ViewPtr view)
86 Eigen::Array2i size_view(view->getRenderer()->GetSize());
88 QPoint qpos_ll = qpos_ul + QPoint(0, size_view[1]-1);
90 QPoint vtkpos_ll = this->qt2vtk(qpos_ll);
95 QPoint ViewCollectionImageWriter::qt2vtk(QPoint qpos)
97 int H = mWidget->height();
98 QPoint vtkpos(qpos.x(), H-1-qpos.y());
105 unsigned char* src =
reinterpret_cast<unsigned char*
>(image->GetScalarPointer());
106 unsigned char* dst =
reinterpret_cast<unsigned char*
>(target->GetScalarPointer());
107 Eigen::Array3i dim_src(image->GetDimensions());
109 CX_ASSERT(target->GetNumberOfScalarComponents()==depth);
110 CX_ASSERT(image->GetNumberOfScalarComponents()==depth);
112 for (
int y=0; y<dim_src[1]; ++y)
114 unsigned char* src =
reinterpret_cast<unsigned char*
>(image->GetScalarPointer(0,y,0));
115 unsigned char* dst =
reinterpret_cast<unsigned char*
>(target->GetScalarPointer(pos.x(),pos.y()+y,0));
116 memcpy(dst, src, dim_src[0]*depth);
141 Eigen::Array4d vp(renderer->GetViewport());
143 Eigen::Array2i origin(renderer->GetOrigin());
144 Eigen::Array2i size(renderer->GetSize());
145 Eigen::Array<int,6,1> extent;
147 extent[1] = size[0]-1;
149 extent[3] = size[1]-1;
152 int frontBuffer =
false;
154 unsigned char *pixels;
158 renderWindow->MakeCurrent();
160 pixels = renderWindow->GetPixelData(origin[0], origin[1], origin[0]+size[0]-1, origin[1]+size[1]-1, frontBuffer);
166 vtkImageImportPtr
import = vtkImageImportPtr::New();
167 import->SetDataScalarTypeToUnsignedChar();
168 import->SetNumberOfScalarComponents(3);
169 import->SetDataExtent(extent.data());
170 import->SetWholeExtent(extent.data());
171 bool takeOwnership =
true;
172 import->SetImportVoidPointer(pixels, !takeOwnership);
174 return import->GetOutput();
180 CX_ASSERT(input->GetNumberOfScalarComponents()==3);
181 CX_ASSERT(input->GetScalarType() == VTK_UNSIGNED_CHAR);
183 unsigned char* ptr =
reinterpret_cast<unsigned char*
>(input->GetScalarPointer());
184 Eigen::Array3i dim(input->GetDimensions());
187 QImage retval(ptr, dim[0], dim[1], dim[0]*3, QImage::Format_RGB888);
189 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