00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036
00037
00038 #ifndef ViewPort3D_H_DEFINED
00039 #define ViewPort3D_H_DEFINED
00040
00041 #include "Util/Types.H"
00042 #include "Image/Image.H"
00043 #include "Image/Pixels.H"
00044 #include "Image/ImageSet.H"
00045 #include "Image/Point2D.H"
00046 #include "Image/Point3D.H"
00047
00048 #ifdef HAVE_GL_GLEW_H
00049 #include <GL/glew.h>
00050 #endif
00051
00052 #include <X11/Xlib.h>
00053 #include <X11/Xutil.h>
00054 #include <GL/gl.h>
00055 #include <GL/glx.h>
00056
00057
00058 #ifdef INVT_HAVE_LIBGLUT
00059 #include <GL/glut.h>
00060 #endif
00061
00062 #include <vector>
00063
00064 typedef GLXContext (*glXCreateContextAttribsARBProc)(Display*, GLXFBConfig, GLXContext, Bool, const int*);
00065
00066 class ViewPort3D
00067 {
00068 public:
00069
00070
00071 struct Line
00072 {
00073 Point2D<float> p1;
00074 Point2D<float> p2;
00075 };
00076
00077
00078 ViewPort3D(int width, int height,
00079 bool wireframe = false, bool useLights = true, bool useFeedback = false);
00080
00081 ~ViewPort3D();
00082
00083 Dims getDims() { return Dims(itsScreenWidth, itsScreenHeight); }
00084
00085
00086 void setWireframeMode(bool val) { itsWireframe = val; }
00087 void setLightsMode(bool val) { itsUseLights = val; }
00088 void setFeedbackMode(bool val) { itsUseFeedback = val; }
00089
00090
00091
00092 void initFrame();
00093
00094 void initProjection();
00095
00096
00097
00098 void initCtx();
00099
00100
00101 Image<PixRGB<byte> > getFrame();
00102 Image<PixRGB<float> > getFrameFloat();
00103
00104
00105 std::vector<ViewPort3D::Line> getFrameLines();
00106
00107
00108
00109 Image<float> getDepthFrame();
00110
00111
00112 Point3D<float> getPosition(Point3D<float> loc);
00113
00114
00115 void setProjectionMatrix(const double cameraParam[3][4]);
00116
00117
00118
00119
00120
00121
00122 void setProjectionMatrix(float fovy, float aspect, float zmin, float zmax);
00123
00124
00125 int paramDecompMat(const double source[3][4],
00126 double cpara[3][4],
00127 double trans[3][4] );
00128
00129
00130 void setCamera ( const Point3D<float> pos, const Point3D<float> rot );
00131
00132 void setCamera( const double trans[3][4]);
00133
00134
00135
00136 void setLights();
00137
00138
00139
00140 void setColor(const PixRGB<byte> color);
00141
00142 void drawGrid(Dims size, Dims step, float height=0);
00143
00144
00145
00146 void drawLine(const Point3D<float>& p1, const Point3D<float>& p2);
00147
00148 void drawRectangle(const Point3D<float> pos,
00149 const Point3D<float> rot,
00150 const float width, const float height,
00151 const PixRGB<byte> color);
00152
00153 void drawCircle(const Point3D<float> pos,
00154 const Point3D<float> rot,
00155 const float radius,
00156 const PixRGB<byte> color);
00157
00158 void drawDisk(const Point3D<float> pos,
00159 const Point3D<float> rot,
00160 const float radius,
00161 const PixRGB<byte> color);
00162
00163 void drawEllipse(const Point3D<float> pos,
00164 const Point3D<float> rot,
00165 const float radiusX, const float radiusY,
00166 const PixRGB<byte> color);
00167
00168
00169
00170
00171
00172 void drawBox(const Point3D<float> pos,
00173 const Point3D<float> rot,
00174 const Point3D<float> size,
00175 const PixRGB<byte> color);
00176
00177
00178 void drawExtrudedContour(const std::vector<Point2D<float> >& contour,
00179 const Point3D<float> pos,
00180 const Point3D<float> rot,
00181 const float thickness,
00182 const PixRGB<byte> color);
00183
00184
00185
00186 void drawSphere(const Point3D<float> pos,
00187 const Point3D<float> rot,
00188 const Point3D<float> size,
00189 const PixRGB<byte> color);
00190
00191
00192 void drawCylinder(const Point3D<float> pos,
00193 const Point3D<float> rot,
00194 const float radius,
00195 const float length,
00196 const PixRGB<byte> color);
00197
00198
00199 void drawCone(const Point3D<float> pos,
00200 const Point3D<float> rot,
00201 const float radius,
00202 const float length,
00203 const PixRGB<byte> color);
00204
00205
00206 void drawCappedCylinder(const Point3D<float> pos,
00207 const Point3D<float> rot,
00208 const float radius,
00209 const float length,
00210 const PixRGB<byte> color);
00211
00212
00213 void drawGround(const Point2D<float> size, const PixRGB<byte> color);
00214
00215
00216
00217 uint generateSphere(int quality);
00218
00219
00220
00221
00222
00223 std::vector<Point2D<float> > triangulate(const std::vector<Point2D<float> >& contour);
00224 bool snip(const std::vector<Point2D<float> > &contour,
00225 int u,int v,int w,int n,int *V);
00226
00227
00228
00229
00230
00231
00232
00233
00234
00235 void drawPatch (double p1[3], double p2[3], double p3[3], int level);
00236
00237
00238
00239
00240 uint addTexture(const Image<PixRGB<byte> >& textureImg);
00241
00242 uint addTexture(const Image<float>& textureImg);
00243
00244
00245 void bindTexture(const uint texId);
00246
00247
00248 void loadTexture(const Image<PixRGB<byte> >& textureImg, uint texId);
00249
00250
00251
00252 #ifdef HAVE_GL_GLEW_H
00253
00254 void printInfoLog(GLhandleARB obj);
00255
00256 GLhandleARB createShader(const char *prog, int type);
00257
00258
00259 void progToTexture(const GLhandleARB prog, const int texId = -1);
00260
00261 #endif
00262
00263
00264
00265 private:
00266 int itsScreenWidth;
00267 int itsScreenHeight;
00268 Point3D<float> itsCameraPosition;
00269 Point3D<float> itsCameraRotation;
00270
00271 bool itsShowRenderWindow;
00272 bool itsWireframe;
00273 bool itsUseLights;
00274 bool itsUseFeedback;
00275 int itsSphereQuality;
00276 int itsCylinderQuality;
00277
00278
00279
00280 uint itsSphereListNum;
00281
00282 bool itsInitGlew;
00283
00284 Display* itsDisplay;
00285 Window itsWin;
00286 GLXContext itsCtx;
00287
00288
00289 double itsProjMatrix[16];
00290 double itsCameraExParam[16];
00291 bool itsUseExParam;
00292
00293
00294 int itsFeedbackBufferSize;
00295 float* itsFeedbackBuffer;
00296
00297
00298
00299
00300 };
00301
00302
00303
00304
00305
00306
00307
00308
00309 #endif //