2 #include <mip_config.h>
3 #ifndef DECS_HAVE_WXWIDGETS
4 # error Your DECS needs WX. Please recompile DECS with USE_WXWIDGETS.
11 #include <Base/Common/BIASpragmaStart.hh>
12 #include <Base/Common/BIASpragmaEnd.hh>
13 #include <Base/Image/ImageConvert.hh>
14 #include <Base/Common/FileHandling.hh>
15 #include <Base/CommonUtils/Param.hh>
17 #include <GLviewer/ContextWX.hh>
18 #include <GLviewer/GLProjectionParametersPerspective.hh>
19 #include <GLviewer/Controller/TrackballControl.hh>
20 #include <GLviewer/Scenes/SceneOpenSceneGraph.hh>
21 #include <GLviewer/Scenes/SceneOcTree3D.hh>
24 #include <wx/listctrl.h>
25 #include <wx/filename.h>
27 #include <Gui/StringConv.hh>
28 #include <Gui/ConsoleRedirectIO.hh>
29 #include <Gui/ImageCanvas.hh>
30 #include <Gui/biasgl.h>
31 #include <Utils/IOUtils.hh>
33 #include <OpenGLFramework/RenderingContext/glfPBuffer.hh>
34 #include <OpenCLFramework/Algorithm/clfTrimmedICP.hh>
35 #include <OpenGLFramework/RenderingContext/glfRenderingContext.hh>
48 class MainFrame :
public wxFrame
51 MainFrame(std::string depthModel, std::string texModel, std::string depthIn, std::string texIn,
int ylast,
double zthres,
bool closeafterfinish,
bool notrefinewithall);
55 void OnExit(wxCommandEvent& event);
56 void OnTimer(wxTimerEvent& event);
57 void OnKey(wxKeyEvent& event);
69 std::string depthModelName_, texModelName_, depthInName_, texInName_;
71 unsigned int overlapPixels_;
73 bool closeAfterFinish_, notrefinewithall_;
86 unsigned int mpc, dpc;
91 BEGIN_EVENT_TABLE(MainFrame, wxFrame)
92 EVT_BUTTON(ID_Exit, MainFrame::OnExit)
93 EVT_TIMER(ID_Timer, MainFrame::OnTimer)
94 EVT_KEY_DOWN(MainFrame::OnKey)
97 void MainFrame::OnKey(wxKeyEvent& event) {
102 void MainFrame::OnExit(wxCommandEvent& ) {
103 glcontext_->Destroy();
107 void MainFrame::OnTimer(wxTimerEvent& ) {
110 if (computationStep_ == 0) {
112 int res = tricp_->Compute(100, 18000);
113 cout <<
"Compute!" << endl;
115 computationStep_ = 1;
116 }
else if (computationStep_ == 1) {
117 if (notrefinewithall_) {
120 outname+=
"-icpaligned.mip";
121 cout << outname << endl;
122 IOUtils::SaveCamera(outname, d2orig, proj);
123 computationStep_ = 3;
127 d2copy.SetProj(proj);
138 FindLargestOverlappingRegion_(proj.GetParameters(), p1.GetParameters(), overlap);
139 cout << overlap << endl;
140 unsigned int corners[4];
141 overlap.
GetCorners(corners[0], corners[1], corners[2], corners[3]);
142 overlapPixels_ = (corners[2] - corners[0]) * (corners[3] - corners[1]) * 2 / 3;
143 std::cout << overlapPixels_ << std::endl;
144 mpc = tricp_->SetModelFromDepthMap(d1copy, amp1c);
145 dpc = tricp_->SetDataFromDepthMap(d2copy, amp2c);
148 computationStep_ = 2;
150 }
else if (computationStep_ == 2) {
153 if (overlapPixels_ > 500) {
154 res = tricp_->Compute(20, overlapPixels_);
156 res = tricp_->Compute(20, 8000);
158 cout <<
"Compute!" << endl;
161 cout << proj << endl;
163 outname =
"aligned-"+outname+
".mip";
164 IOUtils::SaveCamera(outname, d2orig, proj);
165 computationStep_ = 3;
169 }
else if (computationStep_ == 3) {
171 if (closeAfterFinish_) {
177 fbo_.ClearColorBuffer(.0f,.0f,.0f,.0f);
178 fbo_.ClearDepthBuffer(1.0f);
179 batch_.SetVertexBuffer( tricp_->GetModel() );
180 batch_.SetRange(0, mpc);
182 batch_.SetVertexBuffer( tricp_->GetData() );
183 batch_.SetRange(0, dpc);
187 outputTextureColor_.CopyToImage( img );
188 ImageIO::Save(
"test.mip", img);
190 ic_->Show( img,
"img" );
193 _timer.Start(5,
true);
196 MainFrame::MainFrame(std::string depthModel, std::string texModel, std::string depthIn, std::string texIn,
int ylast,
double zthres,
bool closeafterfinish,
bool notrefinewithall)
197 : wxFrame((wxFrame *)NULL, -1,
205 depthModelName_ = depthModel;
206 texModelName_ = texModel;
207 depthInName_ = depthIn;
209 closeAfterFinish_ = closeafterfinish;
210 notrefinewithall_ = notrefinewithall;
215 ic_->SetSize(800,600);
223 IOUtils::LoadCamera(&depthModelName_, depth1, p1);
224 depth1.ParseMetaData();
225 IOUtils::LoadCamera(&depthInName_, depth2);
226 depth2.ParseMetaData();
227 IOUtils::LoadCamera(&texModelName_, amp1);
228 IOUtils::LoadCamera(&texInName_, amp2);
233 unsigned char **a1c = amp1c.GetImageDataArray();
234 unsigned char **a2c = amp2c.GetImageDataArray();
244 float **d1 = depth1.GetImageDataArray();
245 float **d2 = depth2.GetImageDataArray();
246 for (
unsigned int y=0;y<amp1.
GetHeight();y++) {
247 for (
unsigned int x=0;x<amp1.
GetWidth();x++) {
254 if (d1[y][x] > zthres || y > (
unsigned int)ylast) {
257 if (d2[y][x] > zthres || y > (
unsigned int)ylast) {
260 a1c[y][x*3+0] = (
unsigned char)a1[y][x];
264 a2c[y][x*3+1] = (
unsigned char)a2[y][x];;
271 unsigned int w=0,h=0;
287 glcontext_->Init(cfg);
289 computationStep_ = 0;
295 mpc = tricp_->SetModelFromDepthMap(depth1, amp1c);
296 dpc = tricp_->SetDataFromDepthMap(depth2, amp2c);
298 _timer.SetOwner(
this, ID_Timer);
299 _timer.Start(5,
true);
300 cout <<
"camera on" << endl;
302 cout <<
"refresh" << endl;
304 outputTextureDepth_.Create();
305 outputTextureDepth_.Set();
306 outputTextureDepth_.Allocate(w,h, GL_DEPTH_COMPONENT24);
308 outputTextureColor_.Create();
309 outputTextureColor_.Set();
310 outputTextureColor_.Allocate(w,h, GL_RGBA);
314 fbo_.AttachTexture(outputTextureColor_, GL_COLOR_ATTACHMENT0_EXT);
315 fbo_.AttachTexture(outputTextureDepth_, GL_DEPTH_ATTACHMENT_EXT);
316 fbo_.CheckComplete();
319 depthBufferMode_.SetDepthTest(
true);
320 viewport_.SetOrigin(0, 0);
321 viewport_.SetSize(w,h);
325 float zFar = 10000.0f;
326 projectionmatrix.MakeProjectionMatrixNew(*pp, zNear, zFar,
true);
327 modelviewmatrix.MakeViewMatrixNew(*pp);
330 batch_.SetDepthBufferMode(&depthBufferMode_);
331 batch_.SetPrimitiveType(GL_POINTS);
332 batch_.SetViewport(&viewport_);
333 batch_.SetRenderTarget(&fbo_);
334 batch_.SetModelViewMatrix(&modelviewmatrix);
335 batch_.SetProjectionMatrix(&projectionmatrix);
343 vector<ProjectionParametersBase *> source;
344 vector<float **> depths;
349 depths[0] = d1copy.GetImageDataArray();
350 depths[1] = d2copy.GetImageDataArray();
351 cout << source[0] << endl << source[1] << endl;
355 unsigned int xmin = 0, xmax = w, ymin = 0, ymax = h;
356 for (
unsigned int i = 0; i < source.size(); i++) {
359 source[i]->GetImageSize(mx, my);
361 HomgPoint3D point3D = source[i]->UnProjectToPoint(midPoint, depths[i][my/2][mx/2]);
363 midPoint = source[(i+1)%2]->Project(point3D);
364 source[i]->GetFirstBorderPixel(it);
369 point3D = source[i]->UnProjectToPoint(sourcepoint, depths[i] [ (
unsigned int)it.
y][ (
unsigned int)it.
x]);
371 edgepoint = source[(i+1)%2]->Project(point3D);
372 edgepoint.Homogenize();
373 if (edgepoint[0] > 0 && edgepoint[0] < w && edgepoint[1]>0 && edgepoint[1] < h) {
379 if (abs(grad[0]) > abs(grad[1])) {
381 if (edgepoint[1] > ymin) {
385 if (edgepoint[1] < ymax) {
392 if (edgepoint[0] > xmin) {
396 if (edgepoint[0] < xmax) {
402 oldPoint = sourcepoint;
403 }
while (source[i]->GetNextBorderPixel(it));
412 class icpapp :
public wxApp
415 virtual bool OnInit();
418 bool icpapp::OnInit()
424 std::string *mdn = p->
AddParamString(
"depthModel",
"name of depthmap model",
"bp-dud-CAM02Depth-00700.mip",
'm');
425 std::string *mtn = p->
AddParamString(
"texModel",
"name of texture model",
"bp-CAM02Amp-00700.mip",
't');
426 std::string *idn = p->
AddParamString(
"depthInput",
"name of depthmap to be aligned",
"bp-dud-CAM02Depth-00800.mip",
'i');
427 std::string *itn = p->
AddParamString(
"texInput",
"name of texture to be aligned",
"bp-CAM02Amp-00800.mip",
'n');
428 int *ylast = p->
AddParamInt(
"ythres",
"cut image in y dir here", -1, 0, INT_MAX,
'y');
429 double *zthres = p->
AddParamDouble(
"zthres",
"depth threshold" , -1, 0, 10000,
'z');
430 bool *closeme = p->
AddParamBool(
"closeAfterFinish",
"close wx window after finish",
false,
'x');
431 bool *notrefinewithall = p->
AddParamBool(
"notrefineonall",
"z threshold will not be unset after first optimum found",
false);
438 MainFrame* mainFrame =
new MainFrame(*mdn, *mtn, *idn, *itn, *ylast, *zthres, *closeme, *notrefinewithall);
439 mainFrame->Show(
true);
440 SetTopWindow(mainFrame);
448 IMPLEMENT_APP(icpapp)
Defines the usage of the depth buffer.
class for handling different region of interest (ROI) representations...
class HomgPoint2D describes a point with 2 degrees of freedom in projective coordinates.
int SetCorners(unsigned UpperLeftX, unsigned UpperLeftY, unsigned LowerRightX, unsigned LowerRightY)
Sets a rectangular region of interest.
void GetCorners(unsigned &UpperLeftX, unsigned &UpperLeftY, unsigned &LowerRightX, unsigned &LowerRightY) const
Return the region of interest, by saving the coordinates within the variables defined by the paramete...
camera parameters which define the mapping between rays in the camera coordinate system and pixels in...
int ScaleShiftBetween(double Min, double Max)
scales and shifts image so afterwards every pixel has a value between Min and Max ...
bool * AddParamBool(const std::string &name, const std::string &help, bool deflt=false, char cmdshort=0, int Group=GRP_NOSHOW)
double * AddParamDouble(const std::string &name, const std::string &help, double deflt=0.0, double min=-DBL_MAX, double max=DBL_MAX, char cmdshort=0, int Group=GRP_NOSHOW)
display image in wx application, provides zoom and investigation functionality
void Homogenize()
homogenize class data member elements to W==1 by divison by W
A batch represents a single Draw call including all parameters (render states).
unsigned int GetWidth() const
int ParseCommandLine(int &argc, char *argv[])
scan command line arguments for valid parameters
Interface for OpenGL rendering contexts.
const ProjectionParametersBase * GetParameters(unsigned int cam=0) const
const parameter access function
static std::string Basename(const std::string &fullname)
Get file base name without path from given path and filename.
This class hides the underlying projection model, like projection matrix, spherical camera...
class for setting viewports
unsigned int GetHeight() const
GLX pbuffer rendering context.
void SetMaxIterations(unsigned int maxiterations)
class HomgPoint3D describes a point with 3 degrees of freedom in projective coordinates.
Can be used to run along the image border.
virtual int GetImageSize(unsigned int &Width, unsigned int &Height) const
Obtain image dimensions.
double x
If using BorderPixel methods these are the coordinates of the pixel.
This class Param provides generic support for parameters.
A 4x4 matrix in native OpenGL format.
Class for converting an array of wxStrings to an array of non-const ASCII strings.
int * AddParamInt(const std::string &name, const std::string &help, int deflt=0, int min=std::numeric_limits< int >::min(), int max=std::numeric_limits< int >::max(), char cmdshort=0, int Group=GRP_NOSHOW)
For all adding routines:
void ShowData(std::ostream &os=std::cout, int grp=GRP_ALL, bool showenhanced=true)
print all data in group grp including current values to os if grp = GRP_ALL, print all values if show...
Camera parameters which define the mapping between rays in the camera coordinate system and pixels in...
std::string * AddParamString(const std::string &name, const std::string &help, std::string deflt="", char cmdshort=0, int Group=GRP_NOSHOW)
Configuration for a rendering context.
const StorageType ** GetImageDataArray() const
overloaded GetImageDataArray() from ImageBase