Basic Image AlgorithmS Library  2.8.0
 All Classes Namespaces Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
ExampleContextSimpleWx.cpp
1 /*
2 This file is part of the BIAS library (Basic ImageAlgorithmS).
3 
4 Copyright (C) 2003-2009 (see file CONTACT for details)
5 Multimediale Systeme der Informationsverarbeitung
6 Institut fuer Informatik
7 Christian-Albrechts-Universitaet Kiel
8 
9 
10 BIAS is free software; you can redistribute it and/or modify
11 it under the terms of the GNU Lesser General Public License as published by
12 the Free Software Foundation; either version 2.1 of the License, or
13 (at your option) any later version.
14 
15 BIAS is distributed in the hope that it will be useful,
16 but WITHOUT ANY WARRANTY; without even the implied warranty of
17 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 GNU Lesser General Public License for more details.
19 
20 You should have received a copy of the GNU Lesser General Public License
21 along with BIAS; if not, write to the Free Software
22 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
23 */
24 
25 
26 /**
27  @example ExampleContextWx.cpp
28  @relates ContextWX, GLProjectionParametersPerspective, SceneThreeDOutWrapper
29  @brief Example for usage ContextWX, GLProjections and ThreeDOutscenes
30  @ingroup g_examples
31  @ingroup g_glviewer
32  @author MIP, sedlazeck 04/2012
33 */
34 
35 #include <GLviewer/ContextWX.hh>
36 #include <Base/Common/BIASpragmaStart.hh>
37 #include <wx/wx.h>
38 #include <Base/Common/BIASpragmaEnd.hh>
39 
40 #include <GLviewer/Scenes/SceneThreeDOutWrapper.hh>
41 #include <GLviewer/ThreeDOutOpenSceneGraph.hh>
42 
43 #include <Base/Image/Image.hh>
44 #include <Base/Image/ImageIO.hh>
45 
46 #include <GLviewer/GLProjectionParametersPerspective.hh>
47 #include <GLviewer/Controller/TrackballControl.hh>
48 
49 
50 
51 using namespace BIAS;
52 using namespace std;
53 
54 /////////////////////////////////////
55 ////////// main window //////////
56 /////////////////////////////////////
57 
58 class CSimpleWxFrame : public wxFrame
59 {
60 
61 public:
62 
63  CSimpleWxFrame();
64 
65 protected:
66 
67  BIAS::TrackballControl* control_;
68  ContextWX* context_;
69  SceneThreeDOutWrapper sceneWrapper_;
72 
73 };
74 
75 CSimpleWxFrame::CSimpleWxFrame()
76  : wxFrame((wxFrame *)NULL, -1, wxT("Wx"), wxPoint(0, 0), wxSize(800, 600))
77 {
78  // init threeDOut and link to sceneWrapper
79  tdo_ = new ThreeDOutOpenSceneGraph();
80 
81  // create a set of 3D points
82  Vector3<double> p3d_1(-1.0, -1.0, 1.0);
83  Vector3<double> p3d_2(1.0, -1.0, 1.0);
84  Vector3<double> p3d_3(-1.0, 1.0, 1.0);
85  Vector3<double> p3d_4(1.0, 1.0, 1.0);
86 
87  // set point drawing size and add points to threeDout
88  tdo_->SetParamsPointSize(100);
89  tdo_->AddPoint(p3d_1, RGBAuc(255, 0, 0, 128));
90  tdo_->AddPoint(p3d_2, RGBAuc(0, 255, 0, 128));
91  tdo_->AddPoint(p3d_3, RGBAuc(0, 0, 255, 128));
92  tdo_->AddPoint(p3d_4, RGBAuc(255, 255, 0, 128));
93 
94  // add some lines between the points
95  tdo_->AddLine(p3d_1, p3d_2, RGBAuc(255, 0, 0, 128));
96  tdo_->AddLine(p3d_2, p3d_3, RGBAuc(255, 0, 0, 128));
97  tdo_->AddLine(p3d_3, p3d_4, RGBAuc(255, 0, 0, 128));
98  tdo_->AddLine(p3d_4, p3d_1, RGBAuc(255, 0, 0, 128));
99 
100  // SceneThreeDOutWrapper is derived from SceneBase and can
101  // therefore provide the link between scenes in a ThreeDOut(OpenSceneGraph)
102  // object and the ContextWX
103  sceneWrapper_.LinkWithThreeDOut(tdo_);
104 
105  // init control
106  control_ = new TrackballControl();
107  control_->SetPointOfInterest(Vector3<double>(0,0,0));
108 
109  // init GL projection
110  // note: the projection's extrinsics need to be set in order to be able
111  // to see the scene upon starting the program. Otherwise, it can be
112  // difficult to find the scene in 3D space.
113  proj_ = new GLProjectionParametersPerspective();
114  proj_->SetSimplePerspectiveCam(60.0, // field of view in degree
115  400, // image width
116  300); // image height
117  proj_->SetAutoReshapeBehaviour(GLProjectionParametersBase::AutoRescaleParams);
118  proj_->LookAt(Vector3<double>(0,0,-50), // eye - camera center
119  Vector3<double>(0,0,1), // center point to look at
120  Vector3<double>(0,1,0)); // up direction
121  proj_->SubtractFromBackgroundImage(false);
122  proj_->SetZClippingPlanes(0.1,50000);
123 
124  // initialize context
125  context_ = new ContextWX(this, -1, wxDefaultPosition, wxSize(800,600));
126  context_->SetGLProjectionParametersInterface(proj_);
127  Vector4<float> clearColor(1,1,1,0);
128  context_->SetClearColor(clearColor);
129  context_->SetControl(control_);
130  context_->SetAutoClipping(false);
131 
132  // add context to sizer within this wxFrame
133  wxBoxSizer* mainSizer = new wxBoxSizer(wxVERTICAL);
134  mainSizer->Add(context_, 1, wxEXPAND|wxALL|wxALIGN_CENTRE, 0);
135  mainSizer->Fit(this);
136 
137  // show the whole thing
138  Layout();
139  Show(true);
140 
141  // append scene with threeDout stuff in context
142  context_->AppendScene(&sceneWrapper_);
143 
144  // finish context initialization
145  context_->InitializationComplete();
146 }
147 
148 ////////////////////////////////////////
149 ////////// main routine //////////
150 ////////////////////////////////////////
151 
152 class CSimpleWxApp : public wxApp
153 {
154 public:
155  bool OnInit();
156 };
157 
158 bool CSimpleWxApp::OnInit()
159 {
160  wxInitAllImageHandlers();
161  CSimpleWxFrame* mainFrame = new CSimpleWxFrame();
162  mainFrame->Show();
163  return true;
164 }
165 
166 IMPLEMENT_APP(CSimpleWxApp)
rescale internal projection parameters preserving aspect ratio and scale by integer values only...
Context implementation for wxWidgets.
Definition: ContextWX.hh:31
BIAS::Vector4< unsigned char > RGBAuc
Definition: RGBA.hh:47
a class for exporting ThreeDOut objects to OSG scene graphs
Wrapping ThreeDOut OpenGL-functionality.
class for camera movement in trackball mode.
class for rendering with projection parameters of ProjectionParametersPerspective ...