Alphabetical Class Index  Class Hierarchy   File Members   Compound Members   File List  

HUtility.h
00001 // Copyright (c) 1998-2014 by Tech Soft 3D, Inc.
00002 //
00003 // The information contained herein is confidential and proprietary to Tech Soft 3D, Inc.,
00004 // and considered a trade secret as defined under civil and criminal statutes.
00005 // Tech Soft 3D, Inc. shall pursue its civil and criminal remedies in the event of
00006 // unauthorized use or misappropriation of its trade secrets.  Use of this information
00007 // by anyone other than authorized employees of Tech Soft 3D, Inc. is granted only under
00008 // a written non-disclosure agreement, expressly prescribing the scope and manner of such use.
00009 
00010 // HUtility.h : interface of the HUtility class
00011 // Set of utility methods
00012 // All methods are public and static
00013 
00014 
00015 #ifndef _HUTILITY_H
00016 #define _HUTILITY_H
00017 
00018 #ifdef H_PACK_8
00019 #pragma pack(push)
00020 #pragma pack(8)
00021 #endif
00022 
00023 
00024 #include "HTools.h"
00025 #include "hic_types.h"
00026 
00027 class HBaseView;
00028 class HOutputHandlerOptions;
00029 class HSmartSelItem;
00030 class HBaseModel;
00031 
00032 class HShellObject;
00033 
00034 
00035 enum AbsoluteWindowType
00036 {
00037     RelativeLeft,
00038     RelativeRight,
00039     RelativeTop,
00040     RelativeBottom,
00041     NotRelative
00042 };
00043 
00044 class FaceWithNormalInfo
00045 {
00046 public:
00047     FaceWithNormalInfo()
00048     {
00049         nindex = -1;
00050         tcindex = -1;
00051         nextindex = -1;
00052     }
00053     int nindex;
00054     int nextindex;
00055     int tcindex;
00056 };
00057  
00058 
00059 class MVO_API ShellToRegionMapper
00060 {
00061 public:
00062     ShellToRegionMapper();
00063     void AddRegion(HC_KEY originalshell, HC_KEY newshell, int regionnum, bool check = true);
00064     HC_KEY GetOriginalShell(HC_KEY newshell, int regionnum);
00065     int GetRegionsFromOriginalShell(HC_KEY originalshell, HC_KEY **newshells, int &regionnum);
00066     void BuildSegmentTreeRecursive(HC_KEY okey, HC_KEY nkey);
00067     void MapSegmentTree(HC_KEY modelkey);
00068     void AddSegmentMapping(HC_KEY originalshell, HC_KEY segmentkey);
00069 
00070     struct vhash_s *        m_RegionToShellHash;
00071     struct vhash_s *        m_ShellToRegionHash;
00072     struct vhash_s *        m_ShellToSegmentHash;
00073 
00074 };
00075 
00076 
00077 
00078 
00079 
00081 
00084 class MVO_API HShellEdge {
00085 public:
00090     HShellEdge(int iFirst = 0, int iSecond = 0){
00091         Set(iFirst, iSecond);
00092     };
00094     int GetFirst() const { return m_iFirst; };
00096     int GetSecond() const { return m_iSecond; };
00101     void Set(int first, int second) {
00102         /* first should always be < second to eliminate ambiguity. */
00103         if(first < second){
00104             m_iFirst = first;
00105             m_iSecond = second;
00106         } else {
00107             m_iFirst = second;
00108             m_iSecond = first;
00109         }
00110     };
00111 
00112     bool operator<(HShellEdge const & rhs) const {
00113         if(m_iFirst != rhs.m_iFirst)
00114             return m_iFirst < rhs.m_iFirst;
00115         return m_iSecond < rhs.m_iSecond;
00116     }
00117 
00118 private:
00119     int m_iFirst;
00120     int m_iSecond;
00121 };
00122 
00124 
00127 class MVO_API HShellFace{
00128 public:
00133     HShellFace(HShellObject const * pShell, int const iFaceIndex);
00134 
00136     int GetPointCount() const ;
00137 
00139     int GetEdgeCount() const ;
00144     HShellEdge const GetEdge(int const iEdgeIndex) const;
00148     void OpenEdge(int const iEdgeIndex) const;
00152     void CloseEdge() const;
00153 
00154 private:
00155     HShellObject const * m_pShell;
00156     int m_iFaceIndex;
00157     int m_iPointCount;
00158 };
00159 
00161 
00164 class MVO_API HShellRegion{
00165 public:
00170     HShellRegion(HShellObject const * pShell, int const iRegionIndex);
00171     ~HShellRegion(){
00172         delete [] m_pRegionFlist;
00173     }
00176     int GetFaceCount() const;
00181     HShellFace const GetFace(int index) const;
00182 
00183     //void Open() const;
00184     //void Close() const;
00185 private:
00186     HShellObject const * m_pShell;
00187     int m_iRegionIndex;
00188 
00189     int m_iRegionFlistLength;
00190     int *m_pRegionFlist;
00191 };
00192 
00193 
00195 
00198 class MVO_API HShellObject {
00199 public:
00203     HShellObject(HC_KEY kShellKey);
00204     HShellObject(HShellObject const & oShellObj);
00205     ~HShellObject();
00206     
00211     HShellRegion const GetRegion(int const index) const;
00212 
00214     int GetFaceCount() const;
00219     int GetFaceFlistIndex(int index) const;
00220 
00221     //void Open() const;
00222     //void Close() const;
00223 
00225     HC_KEY GetKey() const ;
00227     int GetFlistLen() const ;
00229     int const * GetFlist() const ;
00232     void GetFlist (int *flist) const ;
00233 
00234 private:
00235     int m_iFlistLen;
00236     int * m_pFlist;
00237     mutable int * m_pFaceIndexes;
00238 
00239     HC_KEY m_kShellKey;
00240 };
00241 
00242 
00244 
00247 class MVO_API HShell {
00248 public:
00249     HShell()
00250         :point_list_len(0),
00251         point_list(),
00252         normal_list(),
00253         face_list_len(0),
00254         face_list(0),
00255         face_count(0),
00256         region_count(0),
00257         region_list(0)
00258     {}
00259     ~HShell()
00260     {
00261         /* No need to check for null pointers.  delete already does that. */
00262         delete [] point_list;
00263         delete [] normal_list;
00264         delete [] face_list;
00265         delete [] region_list;
00266     }
00267     int point_list_len;   
00268     HPoint  *point_list;  
00269     HVector *normal_list; 
00270     
00271     int face_list_len;    
00272     int *face_list;       
00273     int face_count;       
00274 
00275     int region_count;     
00276     int *region_list;     
00277 };
00278 
00280 
00284 class MVO_API HShellWrapper {
00285     
00286 public:
00291     HShellWrapper(HC_KEY key) {
00292         m_Points = 0;
00293         m_Flist = 0;
00294         m_VParams = 0;
00295         m_VNormals = 0;
00296         m_VColors = 0;
00297         m_faceregion = 0;
00298         m_totalnumfaceslen = 0;
00299         m_numfaceslen = 0;
00300         m_FNArray = 0;
00301         m_faceindirect = 0;
00302         Set(key);
00303     }
00307     HShellWrapper() {
00308         m_Key = INVALID_KEY;
00309         m_Points = 0;
00310         m_Flist = 0;
00311         m_VParams = 0;
00312         m_VNormals = 0;
00313         m_VColors = 0;
00314         m_flen = 0;
00315         m_plen = 0;
00316         m_totalplen = 0;
00317         m_totalflen = 0;
00318         m_faceregion = 0;
00319         m_totalnumfaceslen = 0;
00320         m_numfaceslen = 0;
00321         m_FNArray = 0;
00322         m_faceindirect = 0;
00323     }
00324     ~HShellWrapper();
00325 
00336     HC_KEY Insert(int plen, HPoint *points, int flen, int *flist, HC_KEY insertkey = INVALID_KEY);
00344     HC_KEY Show(int *plen, HPoint **points, int *flen, int **flist);
00348     HC_KEY GetKey() { return m_Key; }
00352     void  TransformPoints(float *matrix);
00353 
00358     HC_KEY Optimize(char *options);
00364     HC_KEY Optimize2(char *options);
00365 
00366     void MakePolygon(int facelen, int *face, HPoint *points);
00367 
00368 
00371     void OpenOwnerSegment();
00372 
00375     void BeginFaceIteration();
00376     
00379     void EndFaceIteration() { ; };
00380     int GetFace(int facenum, int **face);
00385     int NextFace(int **face);
00386     
00392     void CalculateFaceCenter(int *face, int flen, HPoint *mid);
00399     void AddPoints(HPoint *points, int pnum, HPoint *param = 0,  HPoint *normals = 0, bool AddImmediatly= false);
00406     void AddFace(int *face, int fnum, int regionnum, HPoint *points, HPoint *normals = 0, bool AddImediatly= false);
00413     void AddFaceDirect(int *face, int fnum, bool reverse = false, bool AddImmediatly= false);
00420     void AddFace(HPoint *points, int fnum, bool AddImmediatly= false);
00425     void Set(HC_KEY key);
00432     void Regenerate(HC_KEY newowner = INVALID_KEY, bool makeSegment = true, bool regenerate = false);
00437     void GrowArrays(int fnum);
00443     void GrowPointArray(int fnum, bool gorwvparams = false, bool grownormals = false);
00444 
00445     void GrowPointArray2(int fnum, bool growparamarray = false, bool grownormalarray = false, bool growfnarray = false, bool growcolorarray = false);
00446     void AddNextFaceWithDistinctNormals(HPoint const * points, HPoint const * normals, int const * face1, int const * face2, int fnum);
00447     void AddNextFaceWithDistinctNormalsAndTexture(HPoint const * points, HPoint const * normals, HPoint const * texcor,int const * face1, int const *face2, int const *face3, int fnum);
00448     void AddNextFaceWithDistinctNormalsAndColor(HPoint const *points, HPoint const *normals,int const *face1, int const *face2, HPoint *face3, int fnum);
00449  
00450 
00451     void BeginAddFaces(int pnum);
00452     void EndAddFaces();
00453 
00458     void GrowFaceArray(int fnum);
00459 
00461     void SubdivideOneQuadFace(int *face, HShellWrapper &wrapper, bool generateIsolines, int *facecolorlist, int &fclnum);
00462 
00464     void SubdivideOneQuadFace2(int *face);
00469     void SubdivideQuadFaces(bool GenerateIsolines);
00470 
00474     void SetVertexColors(HPoint *color);
00478     void ShowVertexColors(HPoint *color);
00483     void SetVertexColors(float *findex);
00487     void ShowVertexColors(float *color);
00493     void MakeLod(int lodnum, int percent);
00499     void FindExtents(HPoint &center, HPoint &min, HPoint &max);
00500     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);
00501     void ReplaceWithParameters(int plen, HPoint *points, int flen, int *flist, HPoint *normals, float *params, int paranum, bool emptyshell);
00502     void Replace(int plen, HPoint *points, int flen, int *flist, HPoint *normals = 0, bool emptyshell = false);
00503 
00504     void SetFaceRegion(int regionnum);
00505 
00506     void SetEmptyShell(HC_KEY segmentkey, bool MakeSegment);
00507 
00508 
00509     int m_plen;
00510     int m_flen;
00511     HPoint *m_Points;//<! The list of pointst that define the shell.
00512     HPoint *m_VParams;
00513     HPoint *m_VColors;
00514     HPoint *m_VNormals;
00515     int *m_Flist;
00516     HC_KEY m_Key;
00517  
00519     int m_facepointer;
00521     int m_totalflen;
00523     int m_totalplen;
00524     int m_totalnumfaceslen;
00525     int m_numfaceslen;
00526     int *m_faceregion;
00527     int *m_faceindirect;
00528     FaceWithNormalInfo *m_FNArray;
00529 
00530 };
00531 
00532 
00534 
00537 class MVO_API HCamera {
00538 public:
00539     bool valid;          
00540     HPoint position;     
00541     HPoint target;       
00542     HPoint up_vector;    
00543     float field_width;   
00544     float field_height;  
00545     char projection[128]; 
00546 
00547     HCamera () {
00548         projection[0] = '\0';
00549         valid = false;
00550     }
00551 
00553     inline void InvalidateCamera() { projection[0]='\0'; valid = false; }
00554 
00558     bool CameraDifferent(HCamera &cam);
00559 
00563     bool CameraDifferentByAngle(HCamera &cam);
00564 
00565 
00568     void GetFromView(HBaseView * view);
00569 
00571     void Show() {
00572         HC_Show_Camera (&position, &target, &up_vector, &field_width, &field_height, projection);
00573         valid = true;
00574     };
00575 
00577     void Set() const {
00578         HC_Set_Camera (&position, &target, &up_vector, field_width, field_height, projection);
00579     };
00580 };
00581 
00582 
00584 
00587 class MVO_API HBSurfVertex
00588 {
00589 public:
00590     double      x;  
00591     double      y;  
00592     double      z;  
00593     double      w;  
00594 
00597     inline void Set(double X, double Y, double Z, double W) { x=X, y=Y, z=Z, w=W; }
00598 };
00599 
00601 
00605 class MVO_API HPolyline 
00606 {
00607 public:
00608     int             m_PointCount;       
00609     HPoint          *m_pHPointArray;    
00610     HPolyline       *m_pNextPolyline;   
00611 };
00612 
00614 
00618 class MVO_API HShellVertexData 
00619 {
00620 public:
00621     /* Constructor initializes this object to an invalid state. */
00622     HShellVertexData():m_VertexCount(0), m_pFIndexArraySize(0), m_pFIndexArray(0), m_Key(INVALID_KEY){
00623         m_sType[0] = '\0';
00624     }
00625 
00626     /* Destructor free up the resources this object is using. */
00627     ~HShellVertexData(){
00628         ResetMyself();
00629     }
00630 
00631     /* Sets the key and fills in the members with the correct data for this shell. */
00632     void SetKey(HC_KEY const key);
00633 
00634     /* Return a const string for the type of shell. */
00635     char const * const GetType() const {
00636         return m_sType;
00637     }
00638 
00639     /* Returns the vertex count for this shell. */
00640     int const GetVertexCount() const {
00641         return m_VertexCount;
00642     }
00643 
00644     /* Return the key for the shell */
00645     HC_KEY const GetKey() const {
00646         return m_Key;
00647     }
00648 
00649     /* Return the size the findex array */
00650     int const GetFIndexDataSize() const {
00651         return m_pFIndexArraySize;
00652     }
00653 
00654     /* Returns a const array for the findex values in this shell. */
00655     float const * const GetFIndexData() const {
00656         return m_pFIndexArray;
00657     }
00658 
00659     /* Returns a const array (as an argument) for the findex values in this shell. 
00660        Note that the array must be of the appropriate size, e.g., via a call to GetFIndexDataSize. */
00661     void GetFIndexData(float *data) const;
00662 
00663     void SetFIndexData(int const size, float const * const data);
00664 
00665 private:
00666     void ResetMyself();
00667 
00668     int             m_VertexCount;      
00669     int             m_pFIndexArraySize; 
00670     float           *m_pFIndexArray;    
00671     HC_KEY          m_Key;          
00672     char            m_sType[32];        
00673 };
00674 
00675 
00677 
00679 typedef struct
00680 {
00681     HC_KEY *patharray;      
00682     int len;            
00683 }HShowContentsWithPathType;
00684 
00685 
00686 enum HWindowCorner 
00687 {
00688     TopLeft,        
00689     BottomLeft,        
00690     BottomRight,
00691     TopRight
00692 };
00693 
00694 
00695 
00696 
00697 
00698 
00699 
00701 
00719 class MVO_API HUserOptions 
00720 {
00721 public:
00722 
00723     char * m_data;  
00724     int m_length;   
00725     bool m_valid;
00726 
00728     HUserOptions();
00729 
00731     HUserOptions(const HUserOptions& in_data);
00732 
00733 
00735     ~HUserOptions();
00736 
00737 
00741     bool IsValid();
00742 
00748     const char * Show_User_Options();
00749 
00755     const char * Show_One_Net_User_Option(const char * which);
00756 
00762     const char * Show_One_User_Option(const char * which);
00763 
00769     const char * Show_Net_User_Options();
00770 
00771 
00772 private:
00773 
00774     void clear() {
00775         delete [] m_data;
00776         m_data = 0;
00777         m_length = 0;
00778     };  
00779 
00780 };
00781 
00782 
00783 
00785 
00788 class MVO_API HUtility
00789 {
00790 public:
00791 #undef PI
00792     static const float PI;          
00793 
00794     enum{X, Y, Z, W};   
00795     enum{XY, XZ, YZ};   
00796 
00797     static const float EH_Epsilon;  
00798 
00799 
00806     static void     Order(HPoint* one, HPoint* two);
00807 
00814     static void     Find_Relative_Path(HC_KEY from_seg_key, HC_KEY to_seg_key, char * path);
00815 
00819     static float    GetTime();
00820     
00821 
00826     static void     ClampPointToWindow (HPoint * point);
00827 
00834     static HC_KEY       InsertBox (HPoint const * max, HPoint const * min);
00835 
00843     static HC_KEY       InsertWireframeBox (HPoint * max, HPoint * min);
00844 
00851     static void     GenerateCuboidPoints (HPoint const * max, HPoint const * min, HPoint * points);
00852 
00864     static HC_KEY       InsertRectangle (const char * seg, float x0, float y0, float x1, float y1, float z = 0.0f, bool fill = false);
00865 
00866 
00881     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);
00882 
00889     static void     ComputeDoublePrecisionCrossProduct(double * vector1, double * vector2, double * up);
00890 
00897     static double   ComputeDoublePrecisionDotProduct(double * vector1, double * vector2);
00898 
00904     static double   ComputeDoublePrecisionVectorLength(double * vector1);
00905 
00912     static void     GetViewplaneVectors(HC_KEY segment_key, double * view, double * up);
00913 
00918     static void     NormalizeDoublePrecisionVector(double* vector1);
00919 
00927     static bool PointsEqual(HPoint * point1, HPoint * point2);
00928 
00940     static bool     CreateAxisCircle (HPoint const & center, float radius, int axis, bool convert = true);
00941     
00942 
00949     static void     RotateToVector(HPoint start, HPoint end, bool doTranslation = true);
00950 
00966     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);
00967 
00975     static void     SmoothTransition(HCamera old_camera, const HCamera &new_camera, HBaseView *view);
00976 
00983     static bool     CamerasEqual(const HCamera &camera1, const HCamera &camera2);
00984 
00992     static void     ComputeVectorToVectorRotationMatrix(float *matrix,HPoint v1,HPoint v2);
00993 
01002     static bool     ExtractRGB(char *text,float &r, float &g, float &b);
01003 
01014     static void     TransitionQuaternion(float *quat_old, float *quat_new, float t, float *qt);
01015 
01021     static void     MatrixToQuaternion(float *matrix, float *quaternion);
01022 
01028     static void     QuaternionToMatrix(float * quaternion, float *matrix);
01029 
01038     static void     SmoothQuaternionTransition(HBaseView *m_pView, char *old_seg, char *new_seg, int num_of_transitions);
01039     
01047     static void SmoothMatrixTransition(HBaseView *m_pView, HC_KEY seg_key, float *new_matrix);
01048 
01058     static void MultiSmoothTransitions(HBaseView *m_pView, int num_keys, HC_KEY *seg_key, float *new_matrix, HCamera *new_camera = 0);
01059 
01065     static HPoint GetCentroid(HC_KEY seg_key);
01066     
01073     static HPoint GetTransformedCentroid(HC_KEY seg_key, float * matrix = 0);
01074 
01082     static void URIencode(const char * in_string, MVO_POINTER_SIZED_UINT n, char * out_buffer); 
01090     static void URIdecode(const char * in_string, char * out_buffer, MVO_POINTER_SIZED_UINT * n);
01091 
01100     static void     GetCameraFromMatrix(float *matrix, HPoint *target, HPoint *position, HPoint *up_vector, HPoint *translation);
01101     
01110     static void     GetMatrixFromCamera(HPoint target, HPoint position, HPoint up_vector, HPoint translation, float *matrix);
01111 
01112 
01146     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,
01147                                HPoint &pos, HPoint &target, HPoint &up, char * projection, double &width, double &height, double &near_limit );
01148     
01156     static bool     PushAttribute(const char *attName);
01157 
01166     static void     PushAttribute(const char *attName, const char *attText);
01167     
01175     static bool     PopAttribute(const char *attName);
01176 
01187     static bool     ModifyPushedAttribute(const char *attName, const char *newStyle);
01188 
01195     static bool     ShowPushedAttribute(const char *attName, HUserOptions& attText);
01196 
01209     static void Recursive_Merge_Shells( HShell *total_info, HShell *max_info, bool do_recurse, bool delete_orig_shells = false, bool insert_null_lods = false );
01210 
01217     static HC_KEY   Merge_Shells( bool do_recurse, bool delete_orig_shells = false , bool optimize_shell = true, bool generate_regions = false);
01218 
01226     static HC_KEY   Merge_Shells_Generate_Regions( int num_shells, HC_KEY * shell_keys, bool delete_orig_shells = false );
01227 
01237     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 );
01238 
01246     static bool     Segment_Shell_Allocate( HShell *total_info, HShell *max_info, bool do_recurse );
01247 
01255     static void     Shell_Search( HShell *total_info, HShell *max_info, bool do_recurse );
01256 
01257 
01258 
01269     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);
01270 
01271 
01280     static void     CountShellData(HC_KEY shell_key, int * faces, int * vertices, int * triangles, int * tristrips = 0);
01281  
01288     static void     FindFileNameExtension(const char * filename_in, char * ext_out, int size = -1);
01289 
01296     static void     FindFileNameExtension(__wchar_t const * const filename_in, __wchar_t * ext_out, int size = -1);
01297 #ifdef H_USHORT_OVERLOAD
01298     static void     FindFileNameExtension(unsigned short const * const filename_in, unsigned short * ext_out, int size = -1){
01299         FindFileNameExtension((wchar_t const * const)filename_in, (wchar_t*)ext_out, size);
01300     }
01301 #endif
01302 
01307     static void     FindUnicodeFileNameExtension(const unsigned short * filename_in, char * ext_out);
01308 
01316     static void     FindFileNameAndDirectory(const char * filename_in, char * dir_out, char * filename_out);
01324     static void     FindFileNameAndDirectory(__wchar_t const * filename_in, __wchar_t * dir_out, __wchar_t * filename_out);
01325 
01336     static const char* extra_pointer_format();
01340     static HC_KEY CreateScaleIndependentSegment(const char *segname, bool SetCallback = true);
01341 
01345     static HC_KEY GetScaleIndependentGeomSegmentKey(HC_KEY segkey);
01346 
01350     static void SetScaleIndependentGeomPosition(HC_KEY segkey, float x, float y, float z);
01351  
01355     static void GetScaleIndependentGeomPosition(HC_KEY segkey, float &x, float &y, float &z);
01356 
01360     static void RegisterCallbacks();
01361 
01368     static bool IsModelKey(HC_KEY modelkey, HC_KEY objectkey);
01369 
01377     static HC_KEY UserOptionExists(HC_KEY key, const char *attrib, char *result);
01378 
01395     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);
01396 
01406     static int CalculateKeyPath(HC_KEY startkey, HBaseView *view, HC_KEY *keyarray, int maxarray);
01407 
01412     static          bool SegmentExists(const char *segment);
01413 
01416     static          void UnsetAttributes();  
01417 
01425     static          int IsChildOf(HC_KEY owner, HC_KEY child, HC_KEY *klist = 0);
01426 
01432     static          bool IsIdentityMatrix(float* matrix);
01433 
01440     static          void ComputeShellNormal(HC_KEY skey, HPoint &tnormal);
01441     
01451     static          HC_KEY  SelectUnderCursor(HBaseView *view, float x, float y, bool doSelection = true, bool DeSelect = false);
01452 
01453 
01464     static          HC_KEY  SmartSelectUnderCursor(HBaseView *view, float x, float y, bool doSelection = true, bool DeSelect = false);
01465 
01466 
01473     static          bool ShowOneHeuristic(const char *type, char *res = 0);
01480     static          bool ShowOneRenderingOption(const char *type, char *res = 0);
01481 
01491     static          float EaseInEaseOut(float t, float a, float b, float c);
01492 
01497     static          void UnwindIncludes(HC_KEY &key);
01498 
01505     static          void UnwindIncludes(HC_KEY &newkey, HC_KEY *keys, int count);
01506 
01507 
01514     static          bool SafeSetUserOption(const char * opt);
01515 
01522     static          bool SafeShowUserOption(char * opt);
01523 
01524 
01529     static void ProjectShell(HC_KEY shellkey);
01530 
01537     static HC_KEY MergeShells(HC_KEY shell1, HC_KEY shell2);
01538 
01544     static void ShowModellingMatrix(float *segment_modelling_matrix);
01545     
01552     static void ConvertLocalPixelsToLocalWindow(HBaseView * view, HPoint *in_system , HPoint *out_system = 0);
01553 
01554 
01561     static HC_KEY GrabSegment(HC_KEY key);
01562 
01567 #   define MakeSegment(key) GrabSegment(key)
01568 
01574     static void RenameSegment(HC_KEY segkey, const char *newname);
01575 
01576     
01587     static void InterpolateNormalAlongEdge(HPoint &p1, HPoint &n1, HPoint &p2, HPoint &n2, HPoint &p3, HPoint &n3);
01588 
01594     static void ShowNormals(HC_KEY shellkey, float normallength);
01595 
01601     static bool IsSegmentKey(HC_KEY key);
01602 
01609     static int FindContents(HC_KEY &key);
01610 
01617     static int CalculateMajorAxis(HBaseView *view);
01618 
01619     
01627     static HC_KEY FindOneObject(const char *type, bool l = 0);
01633     static void CloseAllSegments(HC_KEY endkey = INVALID_KEY);
01634 
01639     static void ReadjustTarget(HBaseView *view);
01640 
01645     static bool GetAllowAnimation(HC_KEY key);
01646 
01649     static void SuppressAnimation();
01650     
01658     static int  FindFaceByIndex(int findex, int *flist, int flen);
01659 
01666     static bool ShowOneUserOption(const char *option, char *res);
01667 
01673     static HC_KEY GetNextRenumberedKey(HBaseView *view);
01674 
01680     static void NameSegments(HC_KEY &key, HBaseView *view);
01681     
01687     static void MoveToTemp(HC_KEY movekey, HC_KEY tempkey);
01688 
01699     static void ShowContentsWithPath( const char * entitytypes, struct vlist_s **ret_pathlist, bool storePath = false, bool includeIncludes = true, bool filterIncludes = true);
01700     
01701     
01707     static int ustrlen(unsigned short *text);
01708 
01718     static bool RLECompress(int const in_len,
01719                             unsigned char const * const in_buf,
01720                             int * out_len,
01721                             unsigned char * const out_buf);
01722     
01732     static bool ZlibCompress(int const in_len,
01733                              unsigned char const * const in_buf,
01734                              int & out_len,
01735                              unsigned char * const out_buf);
01736 
01746     static bool ZlibDecompress(int const in_len,
01747                              unsigned char const * const in_buf,
01748                              int & out_len,
01749                              unsigned char * const out_buf);
01755     static unsigned short *uconvert(const char *text);
01756 
01767     static bool BuildIncludePath(HC_KEY objectkey, const HC_KEY *includelist, int ilength, HC_KEY *fullpath, int *fplength, HC_KEY matchkey = INVALID_KEY);
01768 
01775     static void BuildIncludePathFromSelection(HSmartSelItem *sitem, int &plen, HC_KEY *fullpath);
01776 
01777 
01786     static void MakeViewSnapshot(HBaseView * view, int width, int height, char ** data);
01787 
01793     static void MakeViewSnapshot(HBaseView * view, HC_KEY image_key);
01794 
01803     static int ConstrainToVector( const float *matrix_in, const HVector &vector, float *matrix_out ) ;
01804 
01812     static void Camera_To_Transform (HCamera    *camera , float *pos, float *projection_matrix, float *complete_matrix);
01823     static void LocalPixelsToWorld(HCamera *camera, bool righthanded, float xres, float yres, int xwpix, int ywpix, float *result);
01830     static float ComputeAngleBetweenVector(HPoint p1, HPoint p2);
01831     
01832 
01838     static int strlen16( const unsigned short *p16);
01839 
01848     static void CalculateBoundingInfo(HC_KEY startkey, HPoint &min, HPoint &max, HPoint &delta, HPoint &mid);
01849 
01859     static long ClipPolygonAgainstPlane(long vertexCount, const HPoint *vertex,
01860         const float *plane, HPoint *result, bool *noCut = 0);
01861 
01868     static HFileOutputResult TwoPassPrint(const char *driver, HOutputHandlerOptions *options);
01869 
01877     static HC_KEY OpenSegmentFromKey(HC_KEY key, char *segment);
01878 
01879 
01891     static bool IsPointInsideAllEdges( const float *pt,const float *points1, 
01892         int len, const int *face1, const float *plane1, float fudge );
01900     static void IntersectionLinePlane(HPoint *p1, HPoint *p2, HPlane *p, HPoint *res);
01901      
01916     static void MergePointsIntoShell(int num_shell_points, HPoint *plist1, int num_shell_facelist, int *flist1, 
01917                                     int num_merge_points, HPoint *merge_points, HPoint *merge_vectors, 
01918                                     float tolerance, bool AddExtraPoints, int *newpoints, int *newpointslen);
01919 
01920 
01935     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);
01936  
01938     static void MergePolylines();
01939     static void CreateZebraStripeTexture(int width, int height, int stripwidth, bool horizontal, HPixelRGB colorstripes, HPixelRGB colorbackground);
01940 
01948     static void ascii_to_unicode(char const *ascii, unsigned short *unicode);
01949 
01957     static void unicode_to_ascii(unsigned short const *unicode, char *ascii);
01958 
01967     static void BatchRead(HBaseModel * model, const char * directory, const char * extension);
01968 
01976     static void AdjustPositionToPlane(HBaseView *, HPoint &position, HPoint point_in_plane);
01977 
01986     static void CalculateCornerImagePosition(HBaseView *view, int iwidth, int iheight, HWindowCorner corner, float &posx, float &posy);
01987     static void OptimizeModelByGrid(HBaseView *view, ShellToRegionMapper *mapper);
01988     static void DecipherTextureString(char *texdef, char *Source, bool *DownSampling = 0, bool *DownSamplingSet = 0, char *ParameterizationSource = 0,
01989                                      char *InterpolationFilter = 0, char *DecimationFilter = 0, char *Layout = 0, char *Tiling = 0, bool *ValueScaleSet = 0,
01990                                      bool *ValueScale = 0,  float *ValueScaleMin =0, float *ValueScaleMax = 0, char *BlendingMode = 0);
01991 
01992 
01993 private:
01994     static void     scale_segment (HIC_Rendition *rendition,HIC_Segment_Info * geo3); 
01995     static void     activity_change (HIC_Segment *seg, int old_activity, int new_activity); 
01996     static bool     RestoreAttributeFromOption(const char *attName, HUserOptions& attText);
01997     static void     ReplaceCharacter(char *text, char orig, char target);
01998     static bool     SetAttribute(const char *attName, const char *attText);
01999     static bool     ShowAttribute(const char *attName, char *attText);
02000     static void     ShowContentsWithPathAddEntity(HC_KEY key, struct vlist_s *pathlist, int level, HC_KEY *patharray, bool storePath);
02001     static void     ShowContentsWithPathRecursive(HC_KEY key, const char *entitytypes, struct vlist_s *pathlist, HC_KEY *patharray, int level, bool storePath, bool includeIncludes, bool filterIncludes);
02002     static void     SubdivideOneShell(HShellWrapper &myshell, int numx, int numy, int numz, HPoint &totalmin,
02003                                  HPoint &totaldeltadiv, HShellWrapper *shellmatrix, HShellWrapper &leftover, float boxdiagonallength, bool DoCut, int regionnum, ShellToRegionMapper *mapper, HC_KEY newkey);
02004 
02005 
02006 };
02007 
02008 
02009 class MVO_API HQualifiedKey
02010 {
02011 public:
02012     HQualifiedKey(HC_KEY key, HC_KEY * includelist, int includelistlength)
02013     {
02014         m_Key = key;
02015         m_pIncludeList = 0;
02016         m_pIncludeList = new HC_KEY[includelistlength];
02017         for (int i = 0; i < includelistlength; i++)
02018             m_pIncludeList[i] = includelist[i];
02019         m_IncludeListLength = includelistlength;
02020     }
02021     ~HQualifiedKey()
02022     {
02023         delete [] m_pIncludeList;
02024     }
02025 
02026     long MakeHashKey()
02027     {
02028         return MakeHashKey(m_Key, m_IncludeListLength,m_pIncludeList);
02029     }
02030 
02031     static long MakeHashKey(HC_KEY key, int includelength, HC_KEY * includes)
02032     {
02033         long hashkey = static_cast<long>(key);
02034         for (int i = 0; i < includelength; i++)
02035         {
02036             hashkey += static_cast<long>(includes[i]);
02037         }
02038         return hashkey;
02039     }
02040 
02041     HC_KEY m_Key;
02042     HC_KEY * m_pIncludeList;
02043     int m_IncludeListLength;
02044 };
02045 
02046 
02047 
02048 
02049 class MVO_API HMergeShellFace
02050 {
02051 
02052 public:
02053     HMergeShellFace()
02054     {
02055         m_pChildFaces = 0;
02056         m_ChildFaceNum = 0;
02057     }
02058     ~HMergeShellFace()
02059     {
02060         if (m_pChildFaces)
02061             delete [] m_pChildFaces;
02062         if (m_pFlist)
02063             delete [] m_pFlist;
02064 
02065     }
02066     void Init(int * flist);
02067     void MakeChildFaces(int & addpoint, HPoint * points, bool AddExtraPoints, int * newpoints, int * newpointslen);
02068     void Divide(int pnum, HPoint * points);
02069 
02070     bool CheckHit(HPoint & p, HPoint & normal, HPoint * plist, HPoint & pres);
02071     HMergeShellFace * FindHitFaceRecursive(HPoint & p, HPoint & normal, HPoint * plist, HPoint & respoint);
02072     HMergeShellFace * FindHitFace(HPoint & p, HPoint & normal, HPoint * plist, HPoint & respoint)
02073     {        
02074         return FindHitFaceRecursive(p, normal, plist,respoint);  
02075     }
02076     bool CheckIfColinear(HPoint * point);
02077     
02078     int GetLengthRecursive(int l);
02079 
02080     int GetLength()
02081     {
02082         return GetLengthRecursive(0);
02083 
02084     }
02085 
02086     int AddToFacelistRecursive(int * start, int l);
02087             
02088     int AddToFacelist(int * start)
02089     {
02090         return AddToFacelistRecursive(start, 0);
02091 
02092     }
02093  
02094 protected:
02095     HMergeShellFace * m_pChildFaces;
02096     int m_flen;
02097     int * m_pFlist;
02098     int m_ChildFaceNum;
02099 };
02100 
02101 
02102 
02103 class MVO_API ColorPiece{
02104 
02105 public:
02106     ColorPiece(int *index, int len, int col)
02107     {
02108         m_uvindex = new int[len];
02109         m_fllen = new int[len];
02110         m_flindex = new int[len];
02111         for (int i=0;i<len;i++)
02112             m_uvindex[i] = index[i];
02113         m_len = len; 
02114         m_col = col;
02115         m_done = false;
02116 
02117     }
02118     ~ColorPiece()
02119     {
02120         delete [] m_uvindex;
02121         delete [] m_fllen;
02122         delete [] m_flindex;
02123     }
02124     int *m_uvindex;
02125     int *m_fllen;
02126     int *m_flindex;
02127     int m_len;
02128     int m_col;
02129 
02130     bool    m_done;
02131 
02132 };
02133 
02134 class MVO_API ColorPieceList
02135 {
02136 public:
02137     ColorPieceList();
02138     ~ColorPieceList();
02139     void AddColorPiece(int *index, int len, int col);
02140     ColorPiece * FindMatch(int col, int ii, int ii2, int &rpos, int &rlen, bool &reverse);
02141     
02142     struct vlist_s*         m_ColorPieceList;   
02143     
02144     
02145 };
02146 
02147 class MVO_API HVerticalUtility :
02148     public HUtility
02149 {
02150 public:
02151 
02152     static void ColorizePointCloud(HC_KEY const segment);
02153 };
02154 
02155 
02156 
02157 class MVO_API HAbsoluteWindow
02158 {
02159 public:
02160     HAbsoluteWindow(HBaseView *view, HC_KEY key,float xpos, float ypos, float width, float height,  AbsoluteWindowType xpos_type = RelativeLeft, 
02161         AbsoluteWindowType ypos_type = RelativeTop, AbsoluteWindowType width_type = RelativeLeft,
02162         AbsoluteWindowType height_type = RelativeTop, bool sb = false);
02163     HAbsoluteWindow(HBaseView *view, HC_KEY key); 
02164     void DecipherOptions();
02165     void AdjustX(float invalue, AbsoluteWindowType wt, float &outvalue);
02166     void AdjustY(float invalue, AbsoluteWindowType wt, float &outvalue);
02167     bool Adjust();
02168     static void AdjustAll(HBaseView *view);
02169     static bool SetWindow(HBaseView *view,float xpos, float ypos, float width, float height,  AbsoluteWindowType xpos_type = RelativeLeft, 
02170         AbsoluteWindowType ypos_type = RelativeTop, AbsoluteWindowType width_type = RelativeLeft,
02171         AbsoluteWindowType height_type = RelativeTop, bool sb = false);
02172     bool IsPositionInWindow(float x, float y);
02173     static bool IsPositionInWindow(HBaseView *view, float x, float y);
02174     static void CalculateLocalWindowPos(HBaseView *view, float x, float y, float &xout, float &yout);
02175     void CalculateLocalWindowPos(float x, float y, float &xout, float &yout);
02176     static void CalculateOuterWindowPos(HBaseView *view, float x, float y, float &xout, float &yout);
02177     void CalculateOuterWindowPos(float x, float y, float &xout, float &yout);
02178 
02179     
02180 
02181     HBaseView *m_pView;
02182     float m_width;
02183     float m_height;
02184     float m_xpos;
02185     float m_ypos;
02186     AbsoluteWindowType m_xpos_type;
02187     AbsoluteWindowType m_ypos_type;
02188     AbsoluteWindowType m_width_type;
02189     AbsoluteWindowType m_height_type;
02190 
02191     bool m_bShowBackground;
02192 
02193     HC_KEY m_key;
02194 
02195 };
02196 
02197 
02198 
02200 
02215 class MVO_API HUnicodeOptions 
02216 {
02217 public:
02218 
02219     wchar_t* m_data;    
02220     int m_length;   
02221     bool m_valid;
02222 
02224     HUnicodeOptions();
02225 
02227     HUnicodeOptions(const HUnicodeOptions& in_data);
02228 
02229 
02231     ~HUnicodeOptions();
02232 
02233 
02237     bool IsValid();
02238 
02243     const __wchar_t * Show_Unicode_Options();
02244 
02249     const wchar_t* Show_One_Net_Unicode_Option(const __wchar_t* which);
02250 #ifdef _MSC_VER
02251     const unsigned short * Show_One_Net_Unicode_Option(const unsigned short * which);
02252 #endif
02253 
02258     const wchar_t * Show_One_Unicode_Option(const __wchar_t * which);
02259 #ifdef _MSC_VER
02260     const unsigned short * Show_One_Unicode_Option(const unsigned short * which);
02261 #endif
02262 
02266     const __wchar_t* Show_Net_Unicode_Options();
02267 
02268 private:
02269 
02270     void clear() {
02271         delete [] m_data;
02272         m_data = 0;
02273         m_length = 0;
02274         m_valid = false;
02275     }
02276 
02277 };
02278 
02279 
02280 
02281 class BREP_Topology;
02282 
02283 class BREP_Edge
02284 {
02285 public:
02286     BREP_Edge(HC_KEY edgekey)
02287     {
02288         m_edgekey = edgekey;
02289         m_vertex1 = INVALID_KEY;
02290         m_vertex2 = INVALID_KEY;
02291     }
02292 
02293     HC_KEY m_edgekey;
02294     HC_KEY m_vertex1;
02295     HC_KEY m_vertex2;
02296  
02297 };
02298 
02299 class BREP_CoEdge
02300 {
02301 public:
02302     BREP_CoEdge(BREP_Edge *edge)
02303     {
02304         m_edge = edge;
02305     }
02306 
02307     BREP_Edge * m_edge;
02308 };
02309 
02310 
02311 class MVO_API BREP_Face
02312 {
02313 public:
02314     BREP_Face(HC_KEY facekey);
02315     ~BREP_Face();
02316 
02317     BREP_Edge * AddCoEdge(BREP_Topology *topol, void *edgeid, HC_KEY edgekey);
02318 
02319     
02320     struct vlist_s *        m_CoEdgeList;
02321     HC_KEY m_facekey;
02322 };
02323 
02324 class MVO_API BREP_Topology
02325 {
02326 public:
02327 
02328     struct vhash_s *        m_FaceHash;
02329 
02330     struct vhash_s *        m_EdgeHash;
02331     struct vhash_s *        m_VertexHash;
02332 
02333     BREP_Face *m_CurrentFace;
02334     BREP_Topology();
02335     ~BREP_Topology();
02336     BREP_Face *AddFace(HC_KEY facekey);
02337     BREP_Face *GetFace(HC_KEY facekey);
02338     BREP_Edge *FindEdge(void *edgeid);
02339     BREP_Edge *AddEdge(void *edgeid, HC_KEY edgekey);
02340     HC_KEY AddVertex(void *vertexid, HPoint vpos);
02341     HC_KEY FindVertex(void *vertexid);
02342 
02343 
02344 
02345     BREP_Face *GetCurrentFace() { return m_CurrentFace; }
02346 
02347 };
02348 
02349 class H_FORMAT_TEXT;
02350 
02351 class MVO_API HBestImageDriver
02352 {
02353 private:
02354     H_FORMAT_TEXT * m_dvr;
02355 public:
02356     HBestImageDriver(char const * prefer_type = 0);
02357     ~HBestImageDriver();
02358 
02359     HC_KEY GetKey() const;
02360 
02361     operator char const* () const;
02362 };
02363 
02364 
02365 class MVO_API HPVOOptions
02366 {
02367     private:
02368         void * impl;
02369 
02370     public:
02371         HPVOOptions(char const * filename);
02372         ~HPVOOptions();
02373         char const * getOption(char const * option) const;
02374 };
02375 
02376 
02377 #ifdef H_PACK_8
02378 #pragma pack(pop)
02379 #endif
02380 
02381 #endif