00001
00031 #ifndef UTILS3D_DEFINED
00032 #define UTILS3D_DEFINED
00033
00034
00035 #include "cv.h"
00036 #include "cxcore.h"
00037 #include "highgui.h"
00038 #include <iostream>
00039
00040
00041 using namespace std;
00042
00043 namespace Utils3D
00044 {
00045 typedef struct _STRAIGHTLINE
00046 {
00047 CvPoint3D32f loc;
00048 CvPoint3D32f dir;
00049 }STRAIGHTLINE;
00050
00051 typedef struct _PLANE
00052 {
00053 CvPoint3D32f loc;
00054 CvPoint3D32f dir1;
00055 CvPoint3D32f dir2;
00056
00057 }PLANE;
00058
00059 typedef struct _PLANE2
00060 {
00061 CvPoint3D32f loc;
00062 CvPoint3D32f norm;
00063 }PLANE2;
00064
00065 inline int sgn ( float in )
00066 {
00067 if ( in > 0)
00068 return 1;
00069 if ( in < 0 )
00070 return -1;
00071 return 0;
00072 }
00073
00075 CvMat* createIdentityMatrix();
00077 CvMat* createRotationMatrixX( double angle );
00079 CvMat* createRotationMatrixY( double angle );
00081 CvMat* createRotationMatrixZ( double angle );
00083 CvMat* createTranslationMatrix( CvPoint3D32f* trans );
00084
00086 CvMat* createRotationCoordinateSystemMatrixX( double angle );
00088 CvMat* createRotationCoordinateSystemMatrixY( double angle );
00090 CvMat* createRotationCoordinateSystemMatrixZ( double angle );
00091
00092 void generatePlaneVectorsFromNormal(CvPoint3D32f*normal,CvPoint3D32f* v1,CvPoint3D32f*v2);
00093
00095 CvMat* createTransformationMatrix(CvPoint3D32f* trans, double rotX, double rotY, double rotZ);
00097
00099 CvMat* createTransformationMatrix(CvPoint3D32f* trans, CvPoint3D32f* rot);
00100
00102 void fillStraightLine(CvPoint3D32f * loc, CvPoint3D32f * dir, STRAIGHTLINE * line);
00104 void fillStraightLine(float locX, float locY, float locZ, float dirX, float dirY, float dirZ, STRAIGHTLINE * line);
00105
00107 void fillPlane(CvPoint3D32f loc, CvPoint3D32f dir1, CvPoint3D32f dir2, PLANE * plane);
00109 void fillPlane(float locX, float locY, float locZ, float dir1X, float dir1Y, float dir1Z, float dir2X, float dir2Y, float dir2Z, PLANE * plane);
00110
00112 void normalize(CvPoint3D32f* vec);
00113
00115 void transformDirection(CvPoint3D32f* dir, CvMat* transformationMat);
00116
00118 void transformPoint(CvPoint3D32f* point, CvMat* transformationMat);
00119
00121 void transformStraightLine(STRAIGHTLINE* line, CvMat* transformationMat);
00122
00124 void transformPlane(PLANE* plane, CvMat* transformationMat);
00125
00130 double intersectLinePlane(STRAIGHTLINE line, PLANE plane);
00131
00132 STRAIGHTLINE intersectPlanes(PLANE2 P1, PLANE2 P2);
00133
00134 double getPointPlaneDistance(PLANE2 P, CvPoint3D32f p);
00135
00136 CvPoint3D32f projectPointOnPlane(PLANE2 P,CvPoint3D32f p);
00137
00138 CvPoint3D32f projectPointOnLine(STRAIGHTLINE L,CvPoint3D32f* p);
00139
00140 double intersectLinePlane(STRAIGHTLINE line, PLANE2 plane);
00141
00142 double distPoints(CvPoint3D32f* p1, CvPoint3D32f * p2);
00143
00144
00145
00147 double dotProd(CvPoint3D32f* p1, CvPoint3D32f* p2 );
00148
00150 double getAngle(CvPoint3D32f* p1, CvPoint3D32f* p2 );
00151
00153 CvPoint3D32f * cAddPoints(CvPoint3D32f* p1, CvPoint3D32f * p2);
00154
00156 void addPoints(CvPoint3D32f* p1, CvPoint3D32f * p2,CvPoint3D32f*res);
00157
00159 CvPoint3D32f * cAddWPoints(CvPoint3D32f * p1, float w1, CvPoint3D32f * p2, float w2 );
00160
00162 void addWPoints(CvPoint3D32f * p1, float w1, CvPoint3D32f * p2, float w2, CvPoint3D32f*np );
00163
00165 CvPoint3D32f * cSubPoints(CvPoint3D32f* p1, CvPoint3D32f * p2);
00166
00168 void subPoints(CvPoint3D32f* p1, CvPoint3D32f * p2,CvPoint3D32f* res);
00169
00171 CvPoint3D32f * cCrossProduct(CvPoint3D32f* p1, CvPoint3D32f* p2);
00172
00174 void crossProduct(CvPoint3D32f* p1, CvPoint3D32f* p2,CvPoint3D32f* np);
00175
00177 CvPoint3D32f * cGetPoint(float x, float y, float z );
00178
00180 CvPoint3D32f * cCopyPoint(CvPoint3D32f* p );
00181
00183 void swapPoints(CvPoint3D32f* p1, CvPoint3D32f* p2);
00184
00186 double getNorm(CvPoint3D32f* p );
00187
00189 void setCoords (CvPoint3D32f * in, CvPoint3D32f * out);
00190
00192 void setCoords (CvPoint3D32f * out, float x, float y, float z);
00193
00195 void scalePoint(CvPoint3D32f* p, double scale);
00196
00198 void orthonormalizePoints(CvPoint3D32f* p1, CvPoint3D32f* p2,CvPoint3D32f*p3);
00199
00201 void orthonormalizePoints(CvPoint3D32f* p1, CvPoint3D32f* p2,CvPoint3D32f*p3,double scale);
00202
00204 CvMat* cGetBasisFrom3Points(CvPoint3D32f* p1, CvPoint3D32f * p2, CvPoint3D32f * p3 );
00205
00206 CvMat* cGetBasisFrom3Points3x3(CvPoint3D32f* p1, CvPoint3D32f * p2, CvPoint3D32f * p3 ) ;
00207 CvMat * createMatrixFrom3Points(CvPoint3D32f* p1, CvPoint3D32f* p2,CvPoint3D32f* p3);
00208
00209 CvMat * cGetMat32fFrom64d(CvMat* mat64f);
00210 CvMat * cGetMat64dFrom32f(CvMat* mat64f);
00211
00212
00214 CvPoint3D32f * cRectifyPoint(CvPoint3D32f * oriPoint, float sensorLenghtScale, float sensorWidthScale, float sensorHeightScale, CvMat * map_matrix);
00215 CvPoint3D32f * cInverseRectifyPoint(CvPoint3D32f * oriPoint, float sensorLenghtScale, float sensorWidthScale, float sensorHeightScale, CvMat * map_matrix);
00217 CvMat* cCalcRectificationMatrix(CvPoint2D32f* oriP1, CvPoint2D32f* oriP2, CvPoint2D32f* oriP3, CvPoint2D32f* oriP4, CvPoint2D32f* dstP1, CvPoint2D32f* dstP2,CvPoint2D32f* dstP3,CvPoint2D32f* dstP4);
00218
00219
00220 float getShortestDistanceBetweenTwoLines( STRAIGHTLINE line1, STRAIGHTLINE line2,float *t1, float *t2);
00221
00222 float getLineParameter(STRAIGHTLINE line, CvPoint3D32f p);
00223
00224 CvPoint3D32f getLinePoint(STRAIGHTLINE line, float param);
00225 }
00226
00227
00228
00229 #endif