00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024 #ifndef __SO_VECTORIZE_ACTION_
00025 #define __SO_VECTORIZE_ACTION_
00026
00027
00028 #include <SbTypes.h>
00029 #include <stdio.h>
00030 #include <Inventor/SbBasic.h>
00031 #include <Inventor/SbColor.h>
00032 #include <Inventor/SbViewportRegion.h>
00033 #include <Inventor/actions/SoAction.h>
00034 #include <Inventor/actions/SoSubAction.h>
00035 #include <Inventor/actions/SoCallbackAction.h>
00036 #include <Inventor/elements/SoAnnoText3RenderPrintElement.h>
00037 #ifndef NO_TGS_OIV
00038 # include <Inventor/nodes/SoImage.h>
00039 #endif
00040 #include <HardCopy/SoHardCopy.h>
00041
00042
00043 #define POINT_TO_MM 0.3527777778F
00044
00045 #ifndef NO_TGS_OIV
00046 class SoMarkerSet;
00047 #endif
00048
00049 class SoNode;
00050 class SoPath;
00051 class SoPathList;
00052 class SoCallbackAction;
00053 class SoPrimitiveVertex;
00054 class SoHLHSRVectorize;
00055
00056 class SoVectorOutput;
00057
00161 class SoVectorizeAction : public SoAction {
00162
00163 SO_ACTION_HEADER_WITH_DEF(SoVectorizeAction);
00164
00165 public:
00166
00167
00168
00169 virtual ~SoVectorizeAction();
00170
00174 enum DimensionUnit {
00178 INCH,
00182 MM,
00186 METER
00187 };
00188
00192 enum ShadeModel {
00198 FLAT,
00199
00206 SMOOTH
00207 };
00208
00212 enum Orientation {
00216 PORTRAIT,
00220 LANDSCAPE
00221 };
00222
00226 enum ColorTranslationMethod {
00230 REVERSE_ONLY_BLACK_AND_WHITE,
00234 AS_IS,
00238 REVERSE
00239 };
00240
00244 enum JoinLineStyle {
00248 NO_JOIN,
00252 MITERED_JOIN,
00256 MITERED_BEVELED_JOIN,
00260 BEVELED_JOIN,
00264 TRIANGULAR_JOIN,
00268 ROUNDED_JOIN
00269 };
00270
00274 enum EndLineStyle {
00275 BUTT_END,
00276 SQUARE_END,
00277 TRIANGULAR_END,
00278 ROUND_END
00279 };
00280
00281
00286 enum HLHSRMode {
00290 NO_HLHSR,
00294 HLHSR_SIMPLE_PAINTER,
00299 HLHSR_PAINTER,
00304 HLHSR_PAINTER_SURFACE_REMOVAL,
00308 HLHSR_RASTER,
00314 HIDDEN_LINES_REMOVAL
00315 };
00316
00317
00325 virtual SoVectorOutput *getVectorOutput() const;
00326
00327
00328
00332 virtual void apply(SoNode *node);
00333
00337 virtual void apply(SoPath *path);
00338
00351 virtual void apply(const SoPathList &pathList, SbBool obeysRules = FALSE);
00352
00433 virtual void beginPage(const SbVec2f &startPagePosition,
00434 const SbVec2f &pageSize,
00435 DimensionUnit u = MM);
00436
00441 virtual void endPage();
00442
00443
00444
00448 virtual void setDrawingDimensions(float w, float h, DimensionUnit u = MM);
00449
00453 virtual void setDrawingDimensions(const SbVec2f &d, DimensionUnit u = MM);
00454
00458 virtual SbVec2f getDrawingDimensions(DimensionUnit u = MM) const;
00459
00463 virtual void setStartPosition(float x, float y, DimensionUnit u = MM);
00464
00468 virtual void setStartPosition(const SbVec2f &p, DimensionUnit u = MM);
00469
00473 virtual SbVec2f getStartPosition(DimensionUnit u = MM) const;
00474
00478 virtual void setOrientation(Orientation o);
00479
00483 virtual Orientation getOrientation() const;
00484
00490 virtual void setBorder(float width) {
00491 SbColor color = SbVec3f(1.,1.,1.);
00492 setBorder(width, color);
00493 }
00494
00499 virtual void setBorder(float width, SbColor color);
00500
00506 virtual void getBorder(float *w, SbColor *color) const;
00507
00512 virtual void setBackgroundColor(SbBool bg) {
00513 SbColor color = SbVec3f(0.,0.,0.);
00514 setBackgroundColor(bg, color);
00515 }
00516
00521 virtual void setBackgroundColor(SbBool bg, SbColor color);
00522
00527 virtual SbBool getBackgroundColor(SbColor *color) const;
00528
00539 virtual void setNominalWidth(float w, DimensionUnit u = MM);
00540
00544 virtual float getNominalWidth(DimensionUnit u = MM) const;
00545
00556 virtual void setLinePatternSize(float w, DimensionUnit u = MM);
00557
00561 virtual float getLinePatternSize(DimensionUnit u = MM) const;
00562
00572 virtual void setPixelImageSize(float w, DimensionUnit u = MM);
00573
00577 virtual float getPixelImageSize(DimensionUnit u = MM) const;
00578
00585 virtual void setColorTranslationMethod(ColorTranslationMethod method);
00586
00591 virtual ColorTranslationMethod getColorTranslationMethod() const;
00592
00596 virtual void setLineEndStyle(EndLineStyle style);
00597
00601 virtual EndLineStyle getLineEndStyle() const;
00602
00606 virtual void setLineJoinsStyle(JoinLineStyle style);
00607
00611 virtual JoinLineStyle getLineJoinsStyle() const;
00612
00616 virtual void setMiterLimit(float limit);
00617
00621 virtual float getMiterLimit() const;
00622
00632 virtual void setPenDescription(int num_pens,
00633 const SbColor *colors = 0,
00634 const float *widths = 0,
00635 DimensionUnit u = MM);
00636
00641 virtual void getPenDescription(SbColor *colors,
00642 float *widths,
00643 DimensionUnit u = MM) const;
00644
00648 virtual int getPenNum() const;
00649
00655 virtual void setColorPriority(SbBool priority);
00656
00660 virtual SbBool getColorPriority(void) const;
00661
00700 virtual void setHLHSRMode(HLHSRMode mode)
00701 { m_HLHSRMode = mode; }
00702
00706 HLHSRMode getHLHSRMode() const
00707 { return m_HLHSRMode; }
00708
00709
00711
00716 void setHLHSRRasterQuality(float quality)
00717 { m_HLHSRRasterQuality = quality ; }
00718
00723 float getHLHSRRasterQuality() const
00724 { return m_HLHSRRasterQuality ; }
00726
00728
00733 void setHLHSRRasterCaching(SbBool enable)
00734 { m_HLHSRRasterCaching = enable ; }
00735
00740 SbBool getHLHSRRasterCaching() const
00741 { return m_HLHSRRasterCaching ; }
00743
00754 virtual void enableLighting(SbBool flag)
00755 { m_isLightingEnabled = flag; }
00756
00760 SbBool isLightingEnabled() const
00761 { return m_isLightingEnabled; }
00762
00766 void setShadeModel(ShadeModel model)
00767 { m_shadeModel = model ; }
00768
00772 ShadeModel getShadeModel()
00773 { return m_shadeModel ; }
00774
00792 void setPolygonOffset( float offset )
00793 { m_polyOffset = offset; }
00797 void setLineOffset( float offset )
00798 { m_lineOffset = offset; }
00802 void setMarkerOffset( float offset )
00803 { m_markOffset = offset; }
00807 float getPolygonOffset() const
00808 { return m_polyOffset; }
00812 float getLineOffset() const
00813 { return m_lineOffset; }
00817 float getMarkerOffset() const
00818 { return m_markOffset; }
00819
00820 #if 1 SoDEPRECATED
00823 SoVectorOutput *getOutput() const;
00824
00825 #endif
00827 private:
00828
00830
00838 void setHLHSRRasterTileSize(unsigned short tileSize)
00839 { m_HLHSRRasterTileSize = tileSize ; }
00840
00846 unsigned short getHLHSRRasterTileSize() const
00847 { return m_HLHSRRasterTileSize ; }
00849
00853 static void initClass();
00854 static void exitClass();
00855
00856
00857 private:
00858 SoVectorizeAction();
00859
00860
00861 SoVectorOutput *m_output;
00862
00863
00864 virtual void beginTraversal();
00865 virtual void beginTraversal(SoNode *)
00866 { beginTraversal(); }
00867 virtual void endTraversal();
00868 virtual void endTraversal(SoNode *)
00869 { endTraversal(); }
00870
00871 virtual void writeHeader() = 0;
00872 virtual void writeFooter() = 0;
00873
00874 virtual void setHardwareClip() = 0;
00875
00876
00877 virtual SbBox2f getClippingLimits() const;
00878
00879
00880 virtual void printPolyMark(const SbVec4f *points,
00881 int num_points,
00882 const SbColor *colors,
00883 SbBool color_flag,
00884 float size);
00885 #ifndef NO_TGS_OIV
00886 virtual void printPolyMark(const SbVec4f *points,
00887 int num_points,
00888 const SbColor *colors,
00889 SbBool color_flag,
00890 SoMarkerSet *markerSet);
00891 virtual void printImage(const SbVec4f &origin,
00892 const unsigned char *imagePixels,
00893 SbVec2s &sourceSize,
00894 SbVec2s &requestedSize,
00895 int numComponents,
00896 SoImage::HorAlignment horAlign,
00897 SoImage::VertAlignment vertAlign);
00898 #endif
00899
00900 virtual void printPolyLine(const SbVec4f *points,
00901 int num_points,
00902 const SbColor *colors,
00903 SbBool color_flag,
00904 float thickness,
00905 u_short linePattern,
00906 int linePatternScaleFactor = 1);
00907 virtual void printPolygon(const SbVec4f *points,
00908 int num_points,
00909 const SbColor *colors,
00910 SbBool color_flag,
00911 const SbString &category,
00912 const SbString &name,
00913 const unsigned char *pattern);
00914 virtual void printText2(const SbVec4f point,
00915 const SbColor colors,
00916 const SbString& font_name,
00917 float font_size,
00918 const SbString& string,
00919 int justif,
00920 float angle);
00921
00922
00923 virtual void printBorder() = 0;
00924 virtual void printBackground() = 0;
00925
00926
00927 virtual void penAssignment(SbColor color, float width,
00928 int *ret_ind, float *ret_width);
00929
00930 float getViewportWidth() const;
00931 float getViewportHeight() const;
00932 const SbViewportRegion &getViewportRegion() const;
00933
00934
00935 SbColor translateColor(SbColor color);
00936
00937
00938 float getShiftX() const;
00939 float getShiftY() const;
00940 float getWidth() const;
00941 float getHeight() const;
00942
00943
00944 float getOffsetX() const;
00945 float getOffsetY() const;
00946
00947
00948 virtual void prepareAction(SoCallbackAction &action,
00949 SbBool activateSoAnnotationCB = TRUE);
00950
00951
00952
00953 float m_border_width;
00954 SbColor m_border_color;
00955 SbBool m_background_flag;
00956 SbColor m_background_color;
00957
00958
00959 float m_nominal_width;
00960
00961 float m_linePatternSize;
00962
00963 float m_pixelImageSize;
00964
00965
00966 int m_num_pens;
00967
00968 SbColor *m_color_tab;
00969
00970
00971 EndLineStyle m_line_ends_style;
00972 JoinLineStyle m_line_joins_style;
00973 float m_miter_limit;
00974
00975
00976 SbBool m_isViewportRegionExist;
00977
00978
00979 SbVec2f m_pageSize;
00980
00981
00982 SbVec2f m_startPagePosition;
00983
00984
00985 SbBool m_isMultiPlotPerPage;
00986 SbBool m_isFirstPlotPage;
00987
00988
00989
00990 private:
00991
00992 void drawTriangle(SoCallbackAction *action,
00993 SoPrimitiveVertex *v1,
00994 SoPrimitiveVertex *v2,
00995 SoPrimitiveVertex *v3);
00996 void drawLineSegment(SoCallbackAction *action,
00997 SoPrimitiveVertex *v1,
00998 SoPrimitiveVertex *v2);
00999 SoCallbackAction::Response sendPoints(SoCallbackAction *action);
01000 void drawPoint(SoCallbackAction *action,
01001 SoPrimitiveVertex *v);
01002 SoCallbackAction::Response drawText2(SoCallbackAction *action,
01003 const SoNode *node,
01004 SbBool isAnnoText3 = FALSE);
01005 SoCallbackAction::Response drawText3(SoCallbackAction *action,
01006 const SoNode *node,
01007 SbBool isAnnoText3 = FALSE);
01008 SoCallbackAction::Response drawMarkerSet(SoCallbackAction *action,
01009 const SoNode *node);
01010 SoCallbackAction::Response drawImage(SoCallbackAction *action,
01011 const SoNode *node);
01012
01013
01014 void clipImage(SoCallbackAction *action,
01015 SbVec4f *points,
01016 const SoNode *node);
01017 void clipText(SoCallbackAction *action,
01018 SbVec4f *points,
01019 SbColor color,
01020 SoNode *node,
01021 SbBool isAnnoText3 = FALSE);
01022 void clipPolygon(SoCallbackAction *action,
01023 SbVec4f *points,
01024 int num_points,
01025 SbColor *colors);
01026 void clipPolyLine(SoCallbackAction *action,
01027 SbVec4f *points,
01028 int num_points,
01029 SbColor *colors);
01030 void clipPolyLineFar(SoCallbackAction *action,
01031 SbVec4f *points,
01032 int num_points,
01033 SbColor *colors,
01034 int color_flag);
01035 void clipPolyLineXMin(SoCallbackAction *action,
01036 SbVec4f *points,
01037 int num_points,
01038 SbColor *colors,
01039 int color_flag);
01040 void clipPolyLineXMax(SoCallbackAction *action,
01041 SbVec4f *points,
01042 int num_points,
01043 SbColor *colors,
01044 int color_flag);
01045 void clipPolyLineYMin(SoCallbackAction *action,
01046 SbVec4f *points,
01047 int num_points,
01048 SbColor *colors,
01049 int color_flag);
01050 void clipPolyLineYMax(SoCallbackAction *action,
01051 SbVec4f *points,
01052 int num_points,
01053 SbColor *colors,
01054 int color_flag);
01055 void clipPolyMark(SoCallbackAction *action,
01056 SbVec4f *points,
01057 int num_points,
01058 SbColor *colors
01059 #ifndef NO_TGS_OIV
01060 , SoMarkerSet *markerSet = NULL
01061 #endif
01062 );
01063
01064
01065 SoHLHSRVectorize *getHLHSRVectorize() const
01066 { return m_HLHSRVectorize; }
01067 SoHLHSRVectorize *m_HLHSRVectorize;
01068
01069
01070 void projectPoints(SbVec4f *points, int n);
01071
01072
01073
01074 void setProjectionSource(const SbBox2f &projSrc) ;
01075 void setDefaultProjectionSource() ;
01076
01077 void transformPoints(SoCallbackAction *action, SbVec4f *points, int n);
01078 void transformVecMCToVRC(SoCallbackAction *action, SbVec3f &point);
01079 void transformPointsMCToVRC(SoCallbackAction *action,
01080 SbVec4f *points, int n);
01081 void transformPointsVRCToNPC(SoCallbackAction *action,
01082 SbVec4f *points, int n);
01083 SbColor getColor(SoCallbackAction *action,
01084 int index,
01085 SbBool &isFullyTransparent);
01086 SbColor getLightingColor(SoCallbackAction *action,
01087 const SoPrimitiveVertex *vertex,
01088 const SbVec4f &point,
01089 SbBool &isFullyTransparent);
01090 void computeLightList(SoState *state);
01091 void deleteLightsList();
01092 float getAttenuationFactor(const SoCallbackAction *action,
01093 const SbVec3f &lightLocation,
01094 const SbVec3f &vertexPoint);
01095
01096 float getNormalizedWidth();
01097 float getNormalizedHeight();
01098 float computeFontSizeAngleViewing(SoCallbackAction *action,
01099 float fontSize, float &angle);
01100
01101
01102 void setViewportRegion(SoCallbackAction *action);
01103 void setViewportRegion(const SbViewportRegion &vp)
01104 { m_viewportRegion = vp ; }
01105
01106
01107 static float unitsToMillimeters(float w, DimensionUnit u);
01108 static float millimetersToUnits(float w, DimensionUnit u);
01109
01110
01111 static void drawTriangleCB(void *object,
01112 SoCallbackAction *action,
01113 SoPrimitiveVertex *v1,
01114 SoPrimitiveVertex *v2,
01115 SoPrimitiveVertex *v3);
01116 static void drawLineSegmentCB(void *object,
01117 SoCallbackAction *action,
01118 SoPrimitiveVertex *v1,
01119 SoPrimitiveVertex *v2);
01120 static void drawPointCB(void *object,
01121 SoCallbackAction *action,
01122 SoPrimitiveVertex *v);
01123 static SoCallbackAction::Response drawText2CB(void *object,
01124 SoCallbackAction *action,
01125 const SoNode *node);
01126 static SoCallbackAction::Response drawText3CB(void *object,
01127 SoCallbackAction *action,
01128 const SoNode *node);
01129 static SoCallbackAction::Response drawImageCB(void *object,
01130 SoCallbackAction *action,
01131 const SoNode *node);
01132 static SoCallbackAction::Response sendPointsCB(void *object,
01133 SoCallbackAction *action,
01134 const SoNode *node);
01135 static SoCallbackAction::Response drawAnnoText3CB(void *object,
01136 SoCallbackAction *action,
01137 const SoNode *node);
01138 static SoCallbackAction::Response endDrawAnnoText3CB(void *,
01139 SoCallbackAction *,
01140 const SoNode *);
01141 static SoCallbackAction::Response cameraCB(void *object,
01142 SoCallbackAction *action,
01143 const SoNode *node);
01144 static SoCallbackAction::Response storeAnnotationCB(void *object,
01145 SoCallbackAction *action,
01146 const SoNode *node);
01147
01148
01149 void addDelayedPath(SoPath *path);
01150 void renderDelayedPaths();
01151
01152
01153
01154 float m_shiftX, m_shiftY;
01155 Orientation m_orientation;
01156
01157 float m_width, m_height;
01158
01159
01160 SbViewportRegion m_viewportRegion;
01161
01162 ColorTranslationMethod m_colorTranslationMethod;
01163
01164 float *m_pensWidth;
01165 SbBool m_priority;
01166
01167 int m_numAlloc;
01168 int m_numVertices;
01169 SbVec4f *m_pointList;
01170 SbColor *m_colorList;
01171 HLHSRMode m_HLHSRMode;
01172 float m_HLHSRRasterQuality ;
01173 SbBool m_HLHSRRasterCaching ;
01174 unsigned short m_HLHSRRasterTileSize ;
01175 SbBool m_isAnnoText3Drawn;
01176
01177
01178 SoNodeList m_lightNodesList;
01179 SbPList m_lightsList;
01180 SbBool m_isLightingEnabled;
01181
01182
01183 ShadeModel m_shadeModel ;
01184
01185
01186 float m_polyOffset;
01187 float m_lineOffset;
01188 float m_markOffset;
01189
01190
01191
01192 SbBox2f m_projSrc ;
01193
01194
01195 SoPathList m_delayedPaths;
01196
01197
01198 friend class SoHLHSRVectorize;
01199 friend class SoHLHSRImageVectorizer;
01200 };
01201
01212 class SoVectorOutput
01213 {
01214
01215 public:
01216
01220 SoVectorOutput();
01221
01225 virtual ~SoVectorOutput();
01226
01227 public:
01228
01232 virtual void setFilePointer(FILE *newFP);
01233
01238 virtual FILE *getFilePointer();
01239
01246 SoNONUNICODE virtual SbBool openFile(const char *file_name);
01247
01252 virtual SbBool openFile( const SbString& file_name );
01253
01257 virtual void closeFile();
01258
01259 private:
01260
01261 FILE *m_out_file;
01262 };
01263
01264 #endif //__SO_VECTORIZE_ACTION_
01265
01266