00001 // 00002 // Copyright (c) 2000 by Tech Soft 3D, LLC. 00003 // The information contained herein is confidential and proprietary to 00004 // Tech Soft 3D, LLC., and considered a trade secret as defined under 00005 // civil and criminal statutes. Tech Soft 3D shall pursue its civil 00006 // and criminal remedies in the event of unauthorized use or misappropriation 00007 // of its trade secrets. Use of this information by anyone other than 00008 // authorized employees of Tech Soft 3D, LLC. is granted only under a 00009 // written non-disclosure agreement, expressly prescribing the scope and 00010 // manner of such use. 00011 // 00012 // $Id$ 00013 // 00014 00015 // HUtility.h : interface of the HUtility class 00016 // Set of utility methods 00017 // All methods are public and static 00018 00019 00020 #ifndef _HUTILITY_H 00021 #define _HUTILITY_H 00022 00023 #ifdef H_PACK_8 00024 #pragma pack(push) 00025 #pragma pack(8) 00026 #endif 00027 00028 00029 #include "HTools.h" 00030 #include "hic_types.h" 00031 #include <vector> 00032 00033 class HBaseView; 00034 class HOutputHandlerOptions; 00035 class HSmartSelItem; 00036 class HBaseModel; 00037 00038 class HShellObject; 00039 00040 00041 enum AbsoluteWindowType 00042 { 00043 RelativeLeft, 00044 RelativeRight, 00045 RelativeTop, 00046 RelativeBottom, 00047 NotRelative 00048 }; 00049 00050 class FaceWithNormalInfo 00051 { 00052 public: 00053 FaceWithNormalInfo() 00054 { 00055 nindex = -1; 00056 tcindex = -1; 00057 nextindex = -1; 00058 } 00059 int nindex; 00060 int nextindex; 00061 int tcindex; 00062 }; 00063 00064 00065 class MVO_API ShellToRegionMapper 00066 { 00067 public: 00068 ShellToRegionMapper(); 00069 void AddRegion(HC_KEY originalshell, HC_KEY newshell, int regionnum, bool check = true); 00070 HC_KEY GetOriginalShell(HC_KEY newshell, int regionnum); 00071 int GetRegionsFromOriginalShell(HC_KEY originalshell, HC_KEY **newshells, int ®ionnum); 00072 void BuildSegmentTreeRecursive(HC_KEY okey, HC_KEY nkey); 00073 void MapSegmentTree(HC_KEY modelkey); 00074 void AddSegmentMapping(HC_KEY originalshell, HC_KEY segmentkey); 00075 00076 struct vhash_s * m_RegionToShellHash; 00077 struct vhash_s * m_ShellToRegionHash; 00078 struct vhash_s * m_ShellToSegmentHash; 00079 00080 }; 00081 00082 00083 00084 00085 00087 00090 class MVO_API HShellEdge { 00091 public: 00096 HShellEdge(int iFirst = 0, int iSecond = 0){ 00097 Set(iFirst, iSecond); 00098 }; 00100 int GetFirst() const { return m_iFirst; }; 00102 int GetSecond() const { return m_iSecond; }; 00107 void Set(int first, int second) { 00108 /* first should always be < second to eliminate ambiguity. */ 00109 if(first < second){ 00110 m_iFirst = first; 00111 m_iSecond = second; 00112 } else { 00113 m_iFirst = second; 00114 m_iSecond = first; 00115 } 00116 }; 00117 00118 bool operator<(HShellEdge const & rhs) const { 00119 if(m_iFirst != rhs.m_iFirst) 00120 return m_iFirst < rhs.m_iFirst; 00121 return m_iSecond < rhs.m_iSecond; 00122 } 00123 00124 private: 00125 int m_iFirst; 00126 int m_iSecond; 00127 }; 00128 00130 00133 class MVO_API HShellFace{ 00134 public: 00139 HShellFace(HShellObject const * pShell, int const iFaceIndex); 00140 00142 int GetPointCount() const ; 00143 00145 int GetEdgeCount() const ; 00150 HShellEdge const GetEdge(int const iEdgeIndex) const; 00154 void OpenEdge(int const iEdgeIndex) const; 00158 void CloseEdge() const; 00159 00160 private: 00161 HShellObject const * m_pShell; 00162 int m_iFaceIndex; 00163 int m_iPointCount; 00164 }; 00165 00167 00170 class MVO_API HShellRegion{ 00171 public: 00176 HShellRegion(HShellObject const * pShell, int const iRegionIndex); 00177 ~HShellRegion(){ 00178 delete [] m_pRegionFlist; 00179 } 00182 int GetFaceCount() const; 00187 HShellFace const GetFace(int index) const; 00188 00189 //void Open() const; 00190 //void Close() const; 00191 private: 00192 HShellObject const * m_pShell; 00193 int m_iRegionIndex; 00194 00195 int m_iRegionFlistLength; 00196 int *m_pRegionFlist; 00197 }; 00198 00199 00201 00204 class MVO_API HShellObject { 00205 public: 00209 HShellObject(HC_KEY kShellKey); 00210 HShellObject(HShellObject const & oShellObj); 00211 ~HShellObject(); 00212 00217 HShellRegion const GetRegion(int const index) const; 00218 00220 int GetFaceCount() const; 00225 int GetFaceFlistIndex(int index) const; 00226 00227 //void Open() const; 00228 //void Close() const; 00229 00231 HC_KEY GetKey() const ; 00233 int GetFlistLen() const ; 00235 int const * GetFlist() const ; 00238 void GetFlist (int *flist) const ; 00239 00240 private: 00241 int m_iFlistLen; 00242 int * m_pFlist; 00243 mutable int * m_pFaceIndexes; 00244 00245 HC_KEY m_kShellKey; 00246 }; 00247 00248 00250 00253 class MVO_API HShell { 00254 public: 00255 HShell() 00256 :point_list_len(0), 00257 point_list(), 00258 normal_list(), 00259 face_list_len(0), 00260 face_list(0), 00261 face_count(0), 00262 region_count(0), 00263 region_list(0) 00264 {} 00265 ~HShell() 00266 { 00267 /* No need to check for null pointers. delete already does that. */ 00268 delete [] point_list; 00269 delete [] normal_list; 00270 delete [] face_list; 00271 delete [] region_list; 00272 } 00273 int point_list_len; 00274 HPoint *point_list; 00275 HVector *normal_list; 00276 00277 int face_list_len; 00278 int *face_list; 00279 int face_count; 00280 00281 int region_count; 00282 int *region_list; 00283 }; 00284 00286 00290 class MVO_API HShellWrapper { 00291 00292 public: 00297 HShellWrapper(HC_KEY key) { 00298 m_Points = 0; 00299 m_Flist = 0; 00300 m_VParams = 0; 00301 m_VNormals = 0; 00302 m_VColors = 0; 00303 m_faceregion = 0; 00304 m_totalnumfaceslen = 0; 00305 m_numfaceslen = 0; 00306 m_FNArray = 0; 00307 m_faceindirect = 0; 00308 Set(key); 00309 } 00313 HShellWrapper() { 00314 m_Key = INVALID_KEY; 00315 m_Points = 0; 00316 m_Flist = 0; 00317 m_VParams = 0; 00318 m_VNormals = 0; 00319 m_VColors = 0; 00320 m_flen = 0; 00321 m_plen = 0; 00322 m_totalplen = 0; 00323 m_totalflen = 0; 00324 m_faceregion = 0; 00325 m_totalnumfaceslen = 0; 00326 m_numfaceslen = 0; 00327 m_FNArray = 0; 00328 m_faceindirect = 0; 00329 } 00330 ~HShellWrapper(); 00331 00342 HC_KEY Insert(int plen, HPoint *points, int flen, int *flist, HC_KEY insertkey = INVALID_KEY); 00350 HC_KEY Show(int *plen, HPoint **points, int *flen, int **flist); 00354 HC_KEY GetKey() { return m_Key; } 00358 void TransformPoints(float *matrix); 00359 00364 HC_KEY Optimize(char *options); 00370 HC_KEY Optimize2(char *options); 00371 00372 void MakePolygon(int facelen, int *face, HPoint *points); 00373 00374 00377 void OpenOwnerSegment(); 00378 00381 void BeginFaceIteration(); 00382 00385 void EndFaceIteration() { ; }; 00386 int GetFace(int facenum, int **face); 00391 int NextFace(int **face); 00392 00398 void CalculateFaceCenter(int *face, int flen, HPoint *mid); 00405 void AddPoints(HPoint *points, int pnum, HPoint *param = 0, HPoint *normals = 0, bool AddImmediatly= false); 00412 void AddFace(int *face, int fnum, int regionnum, HPoint *points, HPoint *normals = 0, bool AddImediatly= false); 00419 void AddFaceDirect(int *face, int fnum, bool reverse = false, bool AddImmediatly= false); 00426 void AddFace(HPoint *points, int fnum, bool AddImmediatly= false); 00431 void Set(HC_KEY key); 00438 void Regenerate(HC_KEY newowner = INVALID_KEY, bool makeSegment = true, bool regenerate = false); 00443 void GrowArrays(int fnum); 00449 void GrowPointArray(int fnum, bool gorwvparams = false, bool grownormals = false); 00450 00451 void GrowPointArray2(int fnum, bool growparamarray = false, bool grownormalarray = false, bool growfnarray = false, bool growcolorarray = false); 00452 void AddNextFaceWithDistinctNormals(HPoint const * points, HPoint const * normals, int const * face1, int const * face2, int fnum); 00453 void AddNextFaceWithDistinctNormalsAndTexture(HPoint const * points, HPoint const * normals, HPoint const * texcor,int const * face1, int const *face2, int const *face3, int fnum); 00454 void AddNextFaceWithDistinctNormalsAndColor(HPoint const *points, HPoint const *normals,int const *face1, int const *face2, HPoint *face3, int fnum); 00455 00456 00457 void BeginAddFaces(int pnum); 00458 void EndAddFaces(); 00459 00464 void GrowFaceArray(int fnum); 00465 00467 void SubdivideOneQuadFace(int *face, HShellWrapper &wrapper, bool generateIsolines, int *facecolorlist, int &fclnum); 00468 00470 void SubdivideOneQuadFace2(int *face); 00475 void SubdivideQuadFaces(bool GenerateIsolines); 00476 00480 void SetVertexColors(HPoint *color); 00484 void ShowVertexColors(HPoint *color); 00489 void SetVertexColors(float *findex); 00493 void ShowVertexColors(float *color); 00499 void MakeLod(int lodnum, int percent); 00505 void FindExtents(HPoint ¢er, HPoint &min, HPoint &max); 00506 void ReplaceWithParameters(int plen, HPoint *points, int flen, int *flist, HPoint *normals = 0, float *params = 0, int paranum = 3, HPoint *vcolors = 0, bool emptyshell = false); 00507 void ReplaceWithParameters(int plen, HPoint *points, int flen, int *flist, HPoint *normals, float *params, int paranum, bool emptyshell); 00508 void Replace(int plen, HPoint *points, int flen, int *flist, HPoint *normals = 0, bool emptyshell = false); 00509 00510 void SetFaceRegion(int regionnum); 00511 00512 void SetEmptyShell(HC_KEY segmentkey, bool MakeSegment); 00513 00514 00515 int m_plen; 00516 int m_flen; 00517 HPoint *m_Points;//<! The list of pointst that define the shell. 00518 HPoint *m_VParams; 00519 HPoint *m_VColors; 00520 HPoint *m_VNormals; 00521 int *m_Flist; 00522 HC_KEY m_Key; 00523 00525 int m_facepointer; 00527 int m_totalflen; 00529 int m_totalplen; 00530 int m_totalnumfaceslen; 00531 int m_numfaceslen; 00532 int *m_faceregion; 00533 int *m_faceindirect; 00534 FaceWithNormalInfo *m_FNArray; 00535 00536 }; 00537 00538 00540 00543 class MVO_API HCamera { 00544 public: 00545 bool valid; 00546 HPoint position; 00547 HPoint target; 00548 HPoint up_vector; 00549 float field_width; 00550 float field_height; 00551 char projection[128]; 00552 00553 HCamera () { 00554 projection[0] = '\0'; 00555 valid = false; 00556 } 00557 00559 inline void InvalidateCamera() { projection[0]='\0'; valid = false; } 00560 00564 bool CameraDifferent(HCamera &cam); 00565 00569 bool CameraDifferentByAngle(HCamera &cam); 00570 00571 00574 void GetFromView(HBaseView * view); 00575 00577 void Show() { 00578 HC_Show_Camera (&position, &target, &up_vector, &field_width, &field_height, projection); 00579 valid = true; 00580 }; 00581 00583 void Set() const { 00584 HC_Set_Camera (&position, &target, &up_vector, field_width, field_height, projection); 00585 }; 00586 }; 00587 00588 00590 00593 class MVO_API HBSurfVertex 00594 { 00595 public: 00596 double x; 00597 double y; 00598 double z; 00599 double w; 00600 00603 inline void Set(double X, double Y, double Z, double W) { x=X, y=Y, z=Z, w=W; } 00604 }; 00605 00607 00611 class MVO_API HPolyline 00612 { 00613 public: 00614 int m_PointCount; 00615 HPoint *m_pHPointArray; 00616 HPolyline *m_pNextPolyline; 00617 }; 00618 00620 00624 class MVO_API HShellVertexData 00625 { 00626 public: 00627 /* Constructor initializes this object to an invalid state. */ 00628 HShellVertexData():m_VertexCount(0), m_pFIndexArraySize(0), m_pFIndexArray(0), m_Key(INVALID_KEY){ 00629 m_sType[0] = '\0'; 00630 } 00631 00632 /* Destructor free up the resources this object is using. */ 00633 ~HShellVertexData(){ 00634 ResetMyself(); 00635 } 00636 00637 /* Sets the key and fills in the members with the correct data for this shell. */ 00638 void SetKey(HC_KEY const key); 00639 00640 /* Return a const string for the type of shell. */ 00641 char const * const GetType() const { 00642 return m_sType; 00643 } 00644 00645 /* Returns the vertex count for this shell. */ 00646 int const GetVertexCount() const { 00647 return m_VertexCount; 00648 } 00649 00650 /* Return the key for the shell */ 00651 HC_KEY const GetKey() const { 00652 return m_Key; 00653 } 00654 00655 /* Return the size the findex array */ 00656 int const GetFIndexDataSize() const { 00657 return m_pFIndexArraySize; 00658 } 00659 00660 /* Returns a const array for the findex values in this shell. */ 00661 float const * const GetFIndexData() const { 00662 return m_pFIndexArray; 00663 } 00664 00665 /* Returns a const array (as an argument) for the findex values in this shell. 00666 Note that the array must be of the appropriate size, e.g., via a call to GetFIndexDataSize. */ 00667 void GetFIndexData(float *data) const; 00668 00669 void SetFIndexData(int const size, float const * const data); 00670 00671 private: 00672 void ResetMyself(); 00673 00674 int m_VertexCount; 00675 int m_pFIndexArraySize; 00676 float *m_pFIndexArray; 00677 HC_KEY m_Key; 00678 char m_sType[32]; 00679 }; 00680 00681 00683 00685 typedef struct 00686 { 00687 HC_KEY *patharray; 00688 int len; 00689 }HShowContentsWithPathType; 00690 00691 00692 enum HWindowCorner 00693 { 00694 TopLeft, 00695 BottomLeft, 00696 BottomRight, 00697 TopRight 00698 }; 00699 00700 00701 00702 00703 00704 00705 00707 00725 class MVO_API HUserOptions 00726 { 00727 public: 00728 00729 char * m_data; 00730 int m_length; 00731 bool m_valid; 00732 00734 HUserOptions(); 00735 00737 HUserOptions(const HUserOptions& in_data); 00738 00739 00741 ~HUserOptions(); 00742 00743 00747 bool IsValid(); 00748 00754 const char * Show_User_Options(); 00755 00761 const char * Show_One_Net_User_Option(const char * which); 00762 00768 const char * Show_One_User_Option(const char * which); 00769 00775 const char * Show_Net_User_Options(); 00776 00777 00778 private: 00779 00780 void clear() { 00781 H_SAFE_DELETE_ARRAY(m_data); 00782 m_length = 0; 00783 }; 00784 00785 }; 00786 00787 00788 00790 00793 class MVO_API HUtility 00794 { 00795 public: 00796 #undef PI 00797 static const float PI; 00798 00799 enum{X, Y, Z, W}; 00800 enum{XY, XZ, YZ}; 00801 00802 static const float EH_Epsilon; 00803 00804 00811 static void Order(HPoint* one, HPoint* two); 00812 00819 static void Find_Relative_Path(HC_KEY from_seg_key, HC_KEY to_seg_key, char * path); 00820 00824 static float GetTime(); 00825 00826 00831 static void ClampPointToWindow (HPoint * point); 00832 00839 static HC_KEY InsertBox (HPoint * max, HPoint * min); 00840 00848 static HC_KEY InsertWireframeBox (HPoint * max, HPoint * min); 00849 00856 static void GenerateCuboidPoints (HPoint * max, HPoint * min, HPoint * points); 00857 00869 static HC_KEY InsertRectangle (const char * seg, float x0, float y0, float x1, float y1, float z = 0.0f, bool fill = false); 00870 00871 00886 static void InsertArrow(float stick_length, float tip_length, float stick_radius, float arrow_radius, const char *text, const char *stick_color, const char *tip_color, int num_sides = 6, float tip_falloff = 0.05, bool reverse = true); 00887 00894 static void ComputeDoublePrecisionCrossProduct(double * vector1, double * vector2, double * up); 00895 00902 static double ComputeDoublePrecisionDotProduct(double * vector1, double * vector2); 00903 00909 static double ComputeDoublePrecisionVectorLength(double * vector1); 00910 00917 static void GetViewplaneVectors(HC_KEY segment_key, double * view, double * up); 00918 00923 static void NormalizeDoublePrecisionVector(double* vector1); 00924 00932 static bool PointsEqual(HPoint * point1, HPoint * point2); 00933 00945 static bool CreateAxisCircle (HPoint const & center, float radius, int axis, bool convert = true); 00946 00947 00954 static void RotateToVector(HPoint start, HPoint end, bool doTranslation = true); 00955 00971 static void SmoothTransition(const HPoint &co, const HPoint &to, const HPoint &uo, float fieldwidtho, float fieldheighto, const HPoint &cn, const HPoint &tn, const HPoint &un, float fieldwidthn, float fieldheightn, HBaseView *view); 00972 00980 static void SmoothTransition(HCamera old_camera, const HCamera &new_camera, HBaseView *view); 00981 00988 static bool CamerasEqual(const HCamera &camera1, const HCamera &camera2); 00989 00997 static void ComputeVectorToVectorRotationMatrix(float *matrix,HPoint v1,HPoint v2); 00998 01007 static bool ExtractRGB(char *text,float &r, float &g, float &b); 01008 01019 static void TransitionQuaternion(float *quat_old, float *quat_new, float t, float *qt); 01020 01026 static void MatrixToQuaternion(float *matrix, float *quaternion); 01027 01033 static void QuaternionToMatrix(float * quaternion, float *matrix); 01034 01043 static void SmoothQuaternionTransition(HBaseView *m_pView, char *old_seg, char *new_seg, int num_of_transitions); 01044 01052 static void SmoothMatrixTransition(HBaseView *m_pView, HC_KEY seg_key, float *new_matrix); 01053 01063 static void MultiSmoothTransitions(HBaseView *m_pView, int num_keys, HC_KEY *seg_key, float *new_matrix, HCamera *new_camera = 0); 01064 01070 static HPoint GetCentroid(HC_KEY seg_key); 01071 01078 static HPoint GetTransformedCentroid(HC_KEY seg_key, float * matrix = 0); 01079 01087 static void URIencode(const char * in_string, MVO_POINTER_SIZED_UINT n, char * out_buffer); 01095 static void URIdecode(const char * in_string, char * out_buffer, MVO_POINTER_SIZED_UINT * n); 01096 01105 static void GetCameraFromMatrix(float *matrix, HPoint *target, HPoint *position, HPoint *up_vector, HPoint *translation); 01106 01115 static void GetMatrixFromCamera(HPoint target, HPoint position, HPoint up_vector, HPoint translation, float *matrix); 01116 01117 01151 static void GetCameraFromGLFrustum(double const left, double const right, double const bottom , double const top, double const near_z, double const far_z, bool const perspective, 01152 HPoint &pos, HPoint &target, HPoint &up, char * projection, double &width, double &height, double &near_limit ); 01153 01161 static bool PushAttribute(const char *attName); 01162 01171 static void PushAttribute(const char *attName, const char *attText); 01172 01180 static bool PopAttribute(const char *attName); 01181 01192 static bool ModifyPushedAttribute(const char *attName, const char *newStyle); 01193 01200 static bool ShowPushedAttribute(const char *attName, HUserOptions& attText); 01201 01214 static void Recursive_Merge_Shells( HShell *total_info, HShell *max_info, bool do_recurse, bool delete_orig_shells = false, bool insert_null_lods = false ); 01215 01222 static HC_KEY Merge_Shells( bool do_recurse, bool delete_orig_shells = false , bool optimize_shell = true, bool generate_regions = false); 01223 01231 static HC_KEY Merge_Shells_Generate_Regions( int num_shells, HC_KEY * shell_keys, bool delete_orig_shells = false ); 01232 01242 static void Generate_LODs( bool do_recurse = true, bool delete_orig_shells = false, bool insert_null_lods = false, int n_lod_levels = 2, float reduction_ratio = 0.20 ); 01243 01251 static bool Segment_Shell_Allocate( HShell *total_info, HShell *max_info, bool do_recurse ); 01252 01260 static void Shell_Search( HShell *total_info, HShell *max_info, bool do_recurse ); 01261 01262 01263 01274 static void OptimizeSegmentTree(HC_KEY old_seg_key, HC_KEY *new_seg_key, bool transform_shells = true, bool merge_shells = true, bool create_shell_regions = false); 01275 01276 01285 static void CountShellData(HC_KEY shell_key, int * faces, int * vertices, int * triangles, int * tristrips = 0); 01286 01293 static void FindFileNameExtension(const char * filename_in, char * ext_out, int size = -1); 01294 01301 static void FindFileNameExtension(__wchar_t const * const filename_in, __wchar_t * ext_out, int size = -1); 01302 #ifdef H_USHORT_OVERLOAD 01303 static void FindFileNameExtension(unsigned short const * const filename_in, unsigned short * ext_out, int size = -1){ 01304 FindFileNameExtension((wchar_t const * const)filename_in, (wchar_t*)ext_out, size); 01305 } 01306 #endif 01307 01312 static void FindUnicodeFileNameExtension(const unsigned short * filename_in, char * ext_out); 01313 01321 static void FindFileNameAndDirectory(const char * filename_in, char * dir_out, char * filename_out); 01329 static void FindFileNameAndDirectory(__wchar_t const * filename_in, __wchar_t * dir_out, __wchar_t * filename_out); 01330 01341 static const char* extra_pointer_format(); 01345 static HC_KEY CreateScaleIndependentSegment(const char *segname, bool SetCallback = true); 01346 01350 static HC_KEY GetScaleIndependentGeomSegmentKey(HC_KEY segkey); 01351 01355 static void SetScaleIndependentGeomPosition(HC_KEY segkey, float x, float y, float z); 01356 01360 static void GetScaleIndependentGeomPosition(HC_KEY segkey, float &x, float &y, float &z); 01361 01365 static void RegisterCallbacks(); 01366 01373 static bool IsModelKey(HC_KEY modelkey, HC_KEY objectkey); 01374 01382 static HC_KEY UserOptionExists(HC_KEY key, const char *attrib, char *result); 01383 01400 static void InsertRotatedArrow(float stick_length, float tip_length, float stick_radius, float tip_radius, float distance, int adelta, float rotang, const char *stick_color, const char *tip_color, int num_sides, float tip_falloff, bool reverse); 01401 01411 static int CalculateKeyPath(HC_KEY startkey, HBaseView *view, HC_KEY *keyarray, int maxarray); 01412 01417 static bool SegmentExists(const char *segment); 01418 01421 static void UnsetAttributes(); 01422 01430 static int IsChildOf(HC_KEY owner, HC_KEY child, HC_KEY *klist = 0); 01431 01437 static bool IsIdentityMatrix(float* matrix); 01438 01445 static void ComputeShellNormal(HC_KEY skey, HPoint &tnormal); 01446 01456 static HC_KEY SelectUnderCursor(HBaseView *view, float x, float y, bool doSelection = true, bool DeSelect = false); 01457 01458 01469 static HC_KEY SmartSelectUnderCursor(HBaseView *view, float x, float y, bool doSelection = true, bool DeSelect = false); 01470 01471 01478 static bool ShowOneHeuristic(const char *type, char *res = 0); 01485 static bool ShowOneRenderingOption(const char *type, char *res = 0); 01486 01496 static float EaseInEaseOut(float t, float a, float b, float c); 01497 01502 static void UnwindIncludes(HC_KEY &key); 01503 01510 static void UnwindIncludes(HC_KEY &newkey, HC_KEY *keys, int count); 01511 01512 01519 static bool SafeSetUserOption(const char * opt); 01520 01527 static bool SafeShowUserOption(char * opt); 01528 01529 01534 static void ProjectShell(HC_KEY shellkey); 01535 01542 static HC_KEY MergeShells(HC_KEY shell1, HC_KEY shell2); 01543 01549 static void ShowModellingMatrix(float *segment_modelling_matrix); 01550 01557 static void ConvertLocalPixelsToLocalWindow(HBaseView * view, HPoint *in_system , HPoint *out_system = 0); 01558 01559 01566 static HC_KEY GrabSegment(HC_KEY key); 01567 01572 # define MakeSegment(key) GrabSegment(key) 01573 01579 static void RenameSegment(HC_KEY segkey, const char *newname); 01580 01581 01592 static void InterpolateNormalAlongEdge(HPoint &p1, HPoint &n1, HPoint &p2, HPoint &n2, HPoint &p3, HPoint &n3); 01593 01599 static void ShowNormals(HC_KEY shellkey, float normallength); 01600 01606 static bool IsSegmentKey(HC_KEY key); 01607 01614 static int FindContents(HC_KEY &key); 01615 01622 static int CalculateMajorAxis(HBaseView *view); 01623 01624 01632 static HC_KEY FindOneObject(const char *type, bool l = 0); 01638 static void CloseAllSegments(HC_KEY endkey = INVALID_KEY); 01639 01644 static void ReadjustTarget(HBaseView *view); 01645 01650 static bool GetAllowAnimation(HC_KEY key); 01651 01654 static void SuppressAnimation(); 01655 01663 static int FindFaceByIndex(int findex, int *flist, int flen); 01664 01671 static bool ShowOneUserOption(const char *option, char *res); 01672 01678 static HC_KEY GetNextRenumberedKey(HBaseView *view); 01679 01685 static void NameSegments(HC_KEY &key, HBaseView *view); 01686 01692 static void MoveToTemp(HC_KEY movekey, HC_KEY tempkey); 01693 01704 static void ShowContentsWithPath( const char * entitytypes, struct vlist_s **ret_pathlist, bool storePath = false, bool includeIncludes = true, bool filterIncludes = true); 01705 01706 01712 static int ustrlen(unsigned short *text); 01713 01723 static bool RLECompress(int const in_len, 01724 unsigned char const * const in_buf, 01725 int * out_len, 01726 unsigned char * const out_buf); 01727 01737 static bool ZlibCompress(int const in_len, 01738 unsigned char const * const in_buf, 01739 int & out_len, 01740 unsigned char * const out_buf); 01741 01751 static bool ZlibDecompress(int const in_len, 01752 unsigned char const * const in_buf, 01753 int & out_len, 01754 unsigned char * const out_buf); 01760 static unsigned short *uconvert(const char *text); 01761 01772 static bool BuildIncludePath(HC_KEY objectkey, const HC_KEY *includelist, int ilength, HC_KEY *fullpath, int *fplength, HC_KEY matchkey = INVALID_KEY); 01773 01780 static void BuildIncludePathFromSelection(HSmartSelItem *sitem, int &plen, HC_KEY *fullpath); 01781 01782 01791 static void MakeViewSnapshot(HBaseView * view, int width, int height, char ** data); 01792 01798 static void MakeViewSnapshot(HBaseView * view, HC_KEY image_key); 01799 01808 static int ConstrainToVector( const float *matrix_in, const HVector &vector, float *matrix_out ) ; 01809 01817 static void Camera_To_Transform (HCamera *camera , float *pos, float *projection_matrix, float *complete_matrix); 01828 static void LocalPixelsToWorld(HCamera *camera, bool righthanded, float xres, float yres, int xwpix, int ywpix, float *result); 01835 static float ComputeAngleBetweenVector(HPoint p1, HPoint p2); 01836 01837 01843 static int strlen16( const unsigned short *p16); 01844 01853 static void CalculateBoundingInfo(HC_KEY startkey, HPoint &min, HPoint &max, HPoint &delta, HPoint &mid); 01854 01864 static long ClipPolygonAgainstPlane(long vertexCount, const HPoint *vertex, 01865 const float *plane, HPoint *result, bool *noCut = 0); 01866 01873 static HFileOutputResult TwoPassPrint(const char *driver, HOutputHandlerOptions *options); 01874 01882 static HC_KEY OpenSegmentFromKey(HC_KEY key, char *segment); 01883 01884 01896 static bool IsPointInsideAllEdges( const float *pt,const float *points1, 01897 int len, const int *face1, const float *plane1, float fudge ); 01905 static void IntersectionLinePlane(HPoint *p1, HPoint *p2, HPlane *p, HPoint *res); 01906 01921 static void MergePointsIntoShell(int num_shell_points, HPoint *plist1, int num_shell_facelist, int *flist1, 01922 int num_merge_points, HPoint *merge_points, HPoint *merge_vectors, 01923 float tolerance, bool AddExtraPoints, int *newpoints, int *newpointslen); 01924 01925 01940 static void SubdivideShells(HC_KEY sskey, HC_KEY startkey, HC_KEY newkey, int numx, int numy, int numz, ShellToRegionMapper *mapper = 0, bool DoCut = true, bool DeleteOriginalShells = false, bool breakShells = false); 01941 01943 static void MergePolylines(); 01944 static void CreateZebraStripeTexture(int width, int height, int stripwidth, bool horizontal, HPixelRGB colorstripes, HPixelRGB colorbackground); 01945 01953 static void ascii_to_unicode(char const *ascii, unsigned short *unicode); 01954 01962 static void unicode_to_ascii(unsigned short const *unicode, char *ascii); 01963 01972 static void BatchRead(HBaseModel * model, const char * directory, const char * extension); 01973 01981 static void AdjustPositionToPlane(HBaseView *, HPoint &position, HPoint point_in_plane); 01982 01991 static void CalculateCornerImagePosition(HBaseView *view, int iwidth, int iheight, HWindowCorner corner, float &posx, float &posy); 01992 static void OptimizeModelByGrid(HBaseView *view, ShellToRegionMapper *mapper); 01993 static void DecipherTextureString(char *texdef, char *Source, bool *DownSampling = 0, bool *DownSamplingSet = 0, char *ParameterizationSource = 0, 01994 char *InterpolationFilter = 0, char *DecimationFilter = 0, char *Layout = 0, char *Tiling = 0, bool *ValueScaleSet = 0, 01995 bool *ValueScale = 0, float *ValueScaleMin =0, float *ValueScaleMax = 0, char *BlendingMode = 0); 01996 01997 01998 private: 01999 static void scale_segment (HIC_Rendition *rendition,HIC_Segment_Info * geo3); 02000 static void activity_change (HIC_Segment *seg, int old_activity, int new_activity); 02001 static bool RestoreAttributeFromOption(const char *attName, HUserOptions& attText); 02002 static void ReplaceCharacter(char *text, char orig, char target); 02003 static bool SetAttribute(const char *attName, const char *attText); 02004 static bool ShowAttribute(const char *attName, char *attText); 02005 static void ShowContentsWithPathAddEntity(HC_KEY key, struct vlist_s *pathlist, int level, HC_KEY *patharray, bool storePath); 02006 static void ShowContentsWithPathRecursive(HC_KEY key, const char *entitytypes, struct vlist_s *pathlist, HC_KEY *patharray, int level, bool storePath, bool includeIncludes, bool filterIncludes); 02007 static void SubdivideOneShell(HShellWrapper &myshell, int numx, int numy, int numz, HPoint &totalmin, 02008 HPoint &totaldeltadiv, HShellWrapper *shellmatrix, HShellWrapper &leftover, float boxdiagonallength, bool DoCut, int regionnum, ShellToRegionMapper *mapper, HC_KEY newkey); 02009 02010 02011 }; 02012 02013 struct TwoPassPrintFontInfo 02014 { 02015 TwoPassPrintFontInfo(HC_KEY segmentKey, float size, char * units) 02016 { 02017 m_SegmentKey = segmentKey; 02018 m_Size = size; 02019 strcpy(m_Units, units); 02020 } 02021 02022 HC_KEY m_SegmentKey; 02023 float m_Size; 02024 char m_Units[64]; 02025 }; 02026 02027 02028 class MVO_API HQualifiedKey 02029 { 02030 public: 02031 HQualifiedKey(HC_KEY key, HC_KEY *includelist, int includelistlength) 02032 { 02033 m_Key = key; 02034 m_pIncludeList = 0; 02035 m_pIncludeList = new HC_KEY[includelistlength]; 02036 for (int i=0;i<includelistlength;i++) 02037 m_pIncludeList[i] = includelist[i]; 02038 m_IncludeListLength = includelistlength; 02039 } 02040 ~HQualifiedKey() 02041 { 02042 delete [] m_pIncludeList; 02043 } 02044 02045 long MakeHashKey() 02046 { 02047 return (MakeHashKey(m_Key, m_IncludeListLength,m_pIncludeList)); 02048 } 02049 02050 static long MakeHashKey(HC_KEY key, int includelength, HC_KEY *includes) 02051 { 02052 long hashkey = key; 02053 for (int i=0;i<includelength;i++) 02054 { 02055 hashkey+=includes[i]; 02056 } 02057 return hashkey; 02058 } 02059 02060 02061 HC_KEY m_Key; 02062 HC_KEY *m_pIncludeList; 02063 int m_IncludeListLength; 02064 }; 02065 02066 02067 02068 02069 class MVO_API HMergeShellFace 02070 { 02071 02072 public: 02073 HMergeShellFace() 02074 { 02075 m_pChildFaces = 0; 02076 m_ChildFaceNum = 0; 02077 } 02078 ~HMergeShellFace() 02079 { 02080 if (m_pChildFaces) 02081 delete [] m_pChildFaces; 02082 if (m_pFlist) 02083 delete [] m_pFlist; 02084 02085 } 02086 void Init(int *flist); 02087 void MakeChildFaces(int &addpoint, HPoint *points, bool AddExtraPoints, int *newpoints, int *newpointslen); 02088 void Divide(int pnum, HPoint *points); 02089 02090 bool CheckHit(HPoint &p, HPoint &normal, HPoint *plist, HPoint &pres); 02091 HMergeShellFace *FindHitFaceRecursive(HPoint &p, HPoint &normal, HPoint *plist, HPoint &respoint); 02092 HMergeShellFace *FindHitFace(HPoint &p, HPoint &normal, HPoint *plist, HPoint &respoint) 02093 { 02094 return FindHitFaceRecursive(p, normal, plist,respoint); 02095 } 02096 bool CheckIfColinear(HPoint *point); 02097 02098 int GetLengthRecursive(int l); 02099 02100 02101 int GetLength() 02102 { 02103 return (GetLengthRecursive(0)); 02104 02105 } 02106 02107 int AddToFacelistRecursive(int *start, int l); 02108 02109 02110 int AddToFacelist(int *start) 02111 { 02112 return (AddToFacelistRecursive(start, 0)); 02113 02114 } 02115 02116 02117 protected: 02118 HMergeShellFace *m_pChildFaces; 02119 int m_flen; 02120 int *m_pFlist; 02121 02122 int m_ChildFaceNum; 02123 02124 02125 02126 }; 02127 02128 02129 02130 class MVO_API ColorPiece{ 02131 02132 public: 02133 ColorPiece(int *index, int len, int col) 02134 { 02135 m_uvindex = new int[len]; 02136 m_fllen = new int[len]; 02137 m_flindex = new int[len]; 02138 for (int i=0;i<len;i++) 02139 m_uvindex[i] = index[i]; 02140 m_len = len; 02141 m_col = col; 02142 m_done = false; 02143 02144 } 02145 ~ColorPiece() 02146 { 02147 delete [] m_uvindex; 02148 delete [] m_fllen; 02149 delete [] m_flindex; 02150 } 02151 int *m_uvindex; 02152 int *m_fllen; 02153 int *m_flindex; 02154 int m_len; 02155 int m_col; 02156 02157 bool m_done; 02158 02159 }; 02160 02161 class MVO_API ColorPieceList 02162 { 02163 public: 02164 ColorPieceList(); 02165 ~ColorPieceList(); 02166 void AddColorPiece(int *index, int len, int col); 02167 ColorPiece * FindMatch(int col, int ii, int ii2, int &rpos, int &rlen, bool &reverse); 02168 02169 struct vlist_s* m_ColorPieceList; 02170 02171 02172 }; 02173 02174 class MVO_API HVerticalUtility : 02175 public HUtility 02176 { 02177 public: 02178 02179 static void ColorizePointCloud(HC_KEY const segment); 02180 }; 02181 02182 02183 02184 class MVO_API HAbsoluteWindow 02185 { 02186 public: 02187 HAbsoluteWindow(HBaseView *view, HC_KEY key,float xpos, float ypos, float width, float height, AbsoluteWindowType xpos_type = RelativeLeft, 02188 AbsoluteWindowType ypos_type = RelativeTop, AbsoluteWindowType width_type = RelativeLeft, 02189 AbsoluteWindowType height_type = RelativeTop, bool sb = false); 02190 HAbsoluteWindow(HBaseView *view, HC_KEY key); 02191 void DecipherOptions(); 02192 void AdjustX(float invalue, AbsoluteWindowType wt, float &outvalue); 02193 void AdjustY(float invalue, AbsoluteWindowType wt, float &outvalue); 02194 bool Adjust(); 02195 static void AdjustAll(HBaseView *view); 02196 static bool SetWindow(HBaseView *view,float xpos, float ypos, float width, float height, AbsoluteWindowType xpos_type = RelativeLeft, 02197 AbsoluteWindowType ypos_type = RelativeTop, AbsoluteWindowType width_type = RelativeLeft, 02198 AbsoluteWindowType height_type = RelativeTop, bool sb = false); 02199 bool IsPositionInWindow(float x, float y); 02200 static bool IsPositionInWindow(HBaseView *view, float x, float y); 02201 static void CalculateLocalWindowPos(HBaseView *view, float x, float y, float &xout, float &yout); 02202 void CalculateLocalWindowPos(float x, float y, float &xout, float &yout); 02203 static void CalculateOuterWindowPos(HBaseView *view, float x, float y, float &xout, float &yout); 02204 void CalculateOuterWindowPos(float x, float y, float &xout, float &yout); 02205 02206 02207 02208 HBaseView *m_pView; 02209 float m_width; 02210 float m_height; 02211 float m_xpos; 02212 float m_ypos; 02213 AbsoluteWindowType m_xpos_type; 02214 AbsoluteWindowType m_ypos_type; 02215 AbsoluteWindowType m_width_type; 02216 AbsoluteWindowType m_height_type; 02217 02218 bool m_bShowBackground; 02219 02220 HC_KEY m_key; 02221 02222 }; 02223 02224 02225 02227 02242 class MVO_API HUnicodeOptions 02243 { 02244 public: 02245 02246 wchar_t* m_data; 02247 int m_length; 02248 bool m_valid; 02249 02251 HUnicodeOptions(); 02252 02254 HUnicodeOptions(const HUnicodeOptions& in_data); 02255 02256 02258 ~HUnicodeOptions(); 02259 02260 02264 bool IsValid(); 02265 02270 const __wchar_t * Show_Unicode_Options(); 02271 02276 const wchar_t* Show_One_Net_Unicode_Option(const __wchar_t* which); 02277 #ifdef _MSC_VER 02278 const unsigned short * Show_One_Net_Unicode_Option(const unsigned short * which); 02279 #endif 02280 02285 const wchar_t * Show_One_Unicode_Option(const __wchar_t * which); 02286 #ifdef _MSC_VER 02287 const unsigned short * Show_One_Unicode_Option(const unsigned short * which); 02288 #endif 02289 02293 const __wchar_t* Show_Net_Unicode_Options(); 02294 02295 private: 02296 02297 void clear() { 02298 H_SAFE_DELETE_ARRAY(m_data); 02299 m_length = 0; 02300 m_valid = false; 02301 }; 02302 02303 }; 02304 02305 02306 02307 class BREP_Topology; 02308 02309 class BREP_Edge 02310 { 02311 public: 02312 BREP_Edge(HC_KEY edgekey) 02313 { 02314 m_edgekey = edgekey; 02315 m_vertex1 = INVALID_KEY; 02316 m_vertex2 = INVALID_KEY; 02317 } 02318 02319 HC_KEY m_edgekey; 02320 HC_KEY m_vertex1; 02321 HC_KEY m_vertex2; 02322 02323 }; 02324 02325 class BREP_CoEdge 02326 { 02327 public: 02328 BREP_CoEdge(BREP_Edge *edge) 02329 { 02330 m_edge = edge; 02331 } 02332 02333 BREP_Edge * m_edge; 02334 }; 02335 02336 02337 class MVO_API BREP_Face 02338 { 02339 public: 02340 BREP_Face(HC_KEY facekey); 02341 ~BREP_Face(); 02342 02343 BREP_Edge * AddCoEdge(BREP_Topology *topol, void *edgeid, HC_KEY edgekey); 02344 02345 02346 struct vlist_s * m_CoEdgeList; 02347 HC_KEY m_facekey; 02348 }; 02349 02350 class MVO_API BREP_Topology 02351 { 02352 public: 02353 02354 struct vhash_s * m_FaceHash; 02355 02356 struct vhash_s * m_EdgeHash; 02357 struct vhash_s * m_VertexHash; 02358 02359 BREP_Face *m_CurrentFace; 02360 BREP_Topology(); 02361 ~BREP_Topology(); 02362 BREP_Face *AddFace(HC_KEY facekey); 02363 BREP_Face *GetFace(HC_KEY facekey); 02364 BREP_Edge *FindEdge(void *edgeid); 02365 BREP_Edge *AddEdge(void *edgeid, HC_KEY edgekey); 02366 HC_KEY AddVertex(void *vertexid, HPoint vpos); 02367 HC_KEY FindVertex(void *vertexid); 02368 02369 02370 02371 BREP_Face *GetCurrentFace() { return m_CurrentFace; } 02372 02373 }; 02374 02375 class H_FORMAT_TEXT; 02376 02377 class MVO_API HBestImageDriver 02378 { 02379 private: 02380 H_FORMAT_TEXT * m_dvr; 02381 public: 02382 HBestImageDriver(char const * prefer_type = 0); 02383 ~HBestImageDriver(); 02384 02385 HC_KEY GetKey() const; 02386 02387 operator char const* () const; 02388 }; 02389 02390 02391 class MVO_API HPVOOptions 02392 { 02393 private: 02394 void * impl; 02395 02396 public: 02397 HPVOOptions(char const * filename); 02398 ~HPVOOptions(); 02399 char const * getOption(char const * option) const; 02400 }; 02401 02402 02403 #ifdef H_PACK_8 02404 #pragma pack(pop) 02405 #endif 02406 02407 #endif