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
00158 class SoVectorizeAction : public SoAction {
00159
00160 SO_ACTION_HEADER_WITH_DEF(SoVectorizeAction);
00161
00162 public:
00163
00164
00165
00166 virtual ~SoVectorizeAction();
00167
00171 enum DimensionUnit {
00175 INCH,
00179 MM,
00183 METER
00184 };
00185
00189 enum ShadeModel {
00195 FLAT,
00196
00203 SMOOTH
00204 };
00205
00209 enum Orientation {
00213 PORTRAIT,
00217 LANDSCAPE
00218 };
00219
00223 enum ColorTranslationMethod {
00227 REVERSE_ONLY_BLACK_AND_WHITE,
00231 AS_IS,
00235 REVERSE
00236 };
00237
00241 enum JoinLineStyle {
00245 NO_JOIN,
00249 MITERED_JOIN,
00253 MITERED_BEVELED_JOIN,
00257 BEVELED_JOIN,
00261 TRIANGULAR_JOIN,
00265 ROUNDED_JOIN
00266 };
00267
00271 enum EndLineStyle {
00272 BUTT_END,
00273 SQUARE_END,
00274 TRIANGULAR_END,
00275 ROUND_END
00276 };
00277
00278
00283 enum HLHSRMode {
00287 NO_HLHSR,
00291 HLHSR_SIMPLE_PAINTER,
00296 HLHSR_PAINTER,
00301 HLHSR_PAINTER_SURFACE_REMOVAL,
00305 HLHSR_RASTER,
00311 HIDDEN_LINES_REMOVAL
00312 };
00313
00314
00322 virtual SoVectorOutput *getVectorOutput() const;
00323
00324
00325
00329 virtual void apply(SoNode *node);
00330
00334 virtual void apply(SoPath *path);
00335
00348 virtual void apply(const SoPathList &pathList, SbBool obeysRules = FALSE);
00349
00430 virtual void beginPage(const SbVec2f &startPagePosition,
00431 const SbVec2f &pageSize,
00432 DimensionUnit u = MM);
00433
00438 virtual void endPage();
00439
00440
00441
00445 virtual void setDrawingDimensions(float w, float h, DimensionUnit u = MM);
00446
00450 virtual void setDrawingDimensions(const SbVec2f &d, DimensionUnit u = MM);
00451
00455 virtual SbVec2f getDrawingDimensions(DimensionUnit u = MM) const;
00456
00460 virtual void setStartPosition(float x, float y, DimensionUnit u = MM);
00461
00465 virtual void setStartPosition(const SbVec2f &p, DimensionUnit u = MM);
00466
00470 virtual SbVec2f getStartPosition(DimensionUnit u = MM) const;
00471
00475 virtual void setOrientation(Orientation o);
00476
00480 virtual Orientation getOrientation() const;
00481
00487 virtual void setBorder(float width) {
00488 SbColor color = SbVec3f(1.,1.,1.);
00489 setBorder(width, color);
00490 }
00491
00496 virtual void setBorder(float width, SbColor color);
00497
00503 virtual void getBorder(float *w, SbColor *color) const;
00504
00509 virtual void setBackgroundColor(SbBool bg) {
00510 SbColor color = SbVec3f(0.,0.,0.);
00511 setBackgroundColor(bg, color);
00512 }
00513
00518 virtual void setBackgroundColor(SbBool bg, SbColor color);
00519
00524 virtual SbBool getBackgroundColor(SbColor *color) const;
00525
00536 virtual void setNominalWidth(float w, DimensionUnit u = MM);
00537
00541 virtual float getNominalWidth(DimensionUnit u = MM) const;
00542
00553 virtual void setLinePatternSize(float w, DimensionUnit u = MM);
00554
00558 virtual float getLinePatternSize(DimensionUnit u = MM) const;
00559
00569 virtual void setPixelImageSize(float w, DimensionUnit u = MM);
00570
00574 virtual float getPixelImageSize(DimensionUnit u = MM) const;
00575
00582 virtual void setColorTranslationMethod(ColorTranslationMethod method);
00583
00588 virtual ColorTranslationMethod getColorTranslationMethod() const;
00589
00593 virtual void setLineEndStyle(EndLineStyle style);
00594
00598 virtual EndLineStyle getLineEndStyle() const;
00599
00603 virtual void setLineJoinsStyle(JoinLineStyle style);
00604
00608 virtual JoinLineStyle getLineJoinsStyle() const;
00609
00613 virtual void setMiterLimit(float limit);
00614
00618 virtual float getMiterLimit() const;
00619
00629 virtual void setPenDescription(int num_pens,
00630 const SbColor *colors = 0,
00631 const float *widths = 0,
00632 DimensionUnit u = MM);
00633
00638 virtual void getPenDescription(SbColor *colors,
00639 float *widths,
00640 DimensionUnit u = MM) const;
00641
00645 virtual int getPenNum() const;
00646
00652 virtual void setColorPriority(SbBool priority);
00653
00657 virtual SbBool getColorPriority(void) const;
00658
00697 virtual void setHLHSRMode(HLHSRMode mode)
00698 { m_HLHSRMode = mode; }
00699
00703 HLHSRMode getHLHSRMode() const
00704 { return m_HLHSRMode; }
00705
00706
00708
00713 void setHLHSRRasterQuality(float quality)
00714 { m_HLHSRRasterQuality = quality ; }
00715
00720 float getHLHSRRasterQuality() const
00721 { return m_HLHSRRasterQuality ; }
00723
00725
00730 void setHLHSRRasterCaching(SbBool enable)
00731 { m_HLHSRRasterCaching = enable ; }
00732
00737 SbBool getHLHSRRasterCaching() const
00738 { return m_HLHSRRasterCaching ; }
00740
00751 virtual void enableLighting(SbBool flag)
00752 { m_isLightingEnabled = flag; }
00753
00757 SbBool isLightingEnabled() const
00758 { return m_isLightingEnabled; }
00759
00763 void setShadeModel(ShadeModel model)
00764 { m_shadeModel = model ; }
00765
00769 ShadeModel getShadeModel()
00770 { return m_shadeModel ; }
00771
00789 void setPolygonOffset( float offset )
00790 { m_polyOffset = offset; }
00794 void setLineOffset( float offset )
00795 { m_lineOffset = offset; }
00799 void setMarkerOffset( float offset )
00800 { m_markOffset = offset; }
00804 float getPolygonOffset() const
00805 { return m_polyOffset; }
00809 float getLineOffset() const
00810 { return m_lineOffset; }
00814 float getMarkerOffset() const
00815 { return m_markOffset; }
00816
00817 private:
00818
00820
00828 void setHLHSRRasterTileSize(unsigned short tileSize)
00829 { m_HLHSRRasterTileSize = tileSize ; }
00830
00836 unsigned short getHLHSRRasterTileSize() const
00837 { return m_HLHSRRasterTileSize ; }
00839
00843 static void initClass();
00844 static void exitClass();
00845
00846
00847 private:
00848 SoVectorizeAction();
00849
00850
00851 SoVectorOutput *m_output;
00852
00853
00854 virtual void beginTraversal();
00855 virtual void beginTraversal(SoNode *)
00856 { beginTraversal(); }
00857 virtual void endTraversal();
00858 virtual void endTraversal(SoNode *)
00859 { endTraversal(); }
00860
00861 virtual void writeHeader() = 0;
00862 virtual void writeFooter() = 0;
00863
00864 virtual void setHardwareClip() = 0;
00865
00866
00867 virtual SbBox2f getClippingLimits() const;
00868
00869
00870 virtual void printPolyMark(const SbVec4f *points,
00871 int num_points,
00872 const SbColor *colors,
00873 SbBool color_flag,
00874 float size);
00875 #ifndef NO_TGS_OIV
00876 virtual void printPolyMark(const SbVec4f *points,
00877 int num_points,
00878 const SbColor *colors,
00879 SbBool color_flag,
00880 SoMarkerSet *markerSet);
00881 virtual void printImage(const SbVec4f &origin,
00882 const unsigned char *imagePixels,
00883 SbVec2s &sourceSize,
00884 SbVec2s &requestedSize,
00885 int numComponents,
00886 SoImage::HorAlignment horAlign,
00887 SoImage::VertAlignment vertAlign);
00888 #endif
00889
00890 virtual void printPolyLine(const SbVec4f *points,
00891 int num_points,
00892 const SbColor *colors,
00893 SbBool color_flag,
00894 float thickness,
00895 u_short linePattern,
00896 int linePatternScaleFactor = 1);
00897 virtual void printPolygon(const SbVec4f *points,
00898 int num_points,
00899 const SbColor *colors,
00900 SbBool color_flag,
00901 const SbString &category,
00902 const SbString &name,
00903 const unsigned char *pattern);
00904 virtual void printText2(const SbVec4f point,
00905 const SbColor colors,
00906 const SbString& font_name,
00907 float font_size,
00908 const SbString& string,
00909 int justif,
00910 float angle);
00911
00912
00913 virtual void printBorder() = 0;
00914 virtual void printBackground() = 0;
00915
00916
00917 virtual void penAssignment(SbColor color, float width,
00918 int *ret_ind, float *ret_width);
00919
00920 float getViewportWidth() const;
00921 float getViewportHeight() const;
00922 const SbViewportRegion &getViewportRegion() const;
00923
00924
00925 SbColor translateColor(SbColor color);
00926
00927
00928 float getShiftX() const;
00929 float getShiftY() const;
00930 float getWidth() const;
00931 float getHeight() const;
00932
00933
00934 float getOffsetX() const;
00935 float getOffsetY() const;
00936
00937
00938 virtual void prepareAction(SoCallbackAction &action,
00939 SbBool activateSoAnnotationCB = TRUE);
00940
00941
00942
00943 float m_border_width;
00944 SbColor m_border_color;
00945 SbBool m_background_flag;
00946 SbColor m_background_color;
00947
00948
00949 float m_nominal_width;
00950
00951 float m_linePatternSize;
00952
00953 float m_pixelImageSize;
00954
00955
00956 int m_num_pens;
00957
00958 SbColor *m_color_tab;
00959
00960
00961 EndLineStyle m_line_ends_style;
00962 JoinLineStyle m_line_joins_style;
00963 float m_miter_limit;
00964
00965
00966 SbBool m_isViewportRegionExist;
00967
00968
00969 SbVec2f m_pageSize;
00970
00971
00972 SbVec2f m_startPagePosition;
00973
00974
00975 SbBool m_isMultiPlotPerPage;
00976 SbBool m_isFirstPlotPage;
00977
00978
00979
00980 private:
00981
00982 void drawTriangle(SoCallbackAction *action,
00983 SoPrimitiveVertex *v1,
00984 SoPrimitiveVertex *v2,
00985 SoPrimitiveVertex *v3);
00986 void drawLineSegment(SoCallbackAction *action,
00987 SoPrimitiveVertex *v1,
00988 SoPrimitiveVertex *v2);
00989 SoCallbackAction::Response sendPoints(SoCallbackAction *action);
00990 void drawPoint(SoCallbackAction *action,
00991 SoPrimitiveVertex *v);
00992 SoCallbackAction::Response drawText2(SoCallbackAction *action,
00993 const SoNode *node,
00994 SbBool isAnnoText3 = FALSE);
00995 SoCallbackAction::Response drawText3(SoCallbackAction *action,
00996 const SoNode *node,
00997 SbBool isAnnoText3 = FALSE);
00998 SoCallbackAction::Response drawMarkerSet(SoCallbackAction *action,
00999 const SoNode *node);
01000 SoCallbackAction::Response drawImage(SoCallbackAction *action,
01001 const SoNode *node);
01002
01003
01004 void clipImage(SoCallbackAction *action,
01005 SbVec4f *points,
01006 const SoNode *node);
01007 void clipText(SoCallbackAction *action,
01008 SbVec4f *points,
01009 SbColor color,
01010 SoNode *node,
01011 SbBool isAnnoText3 = FALSE);
01012 void clipPolygon(SoCallbackAction *action,
01013 SbVec4f *points,
01014 int num_points,
01015 SbColor *colors);
01016 void clipPolyLine(SoCallbackAction *action,
01017 SbVec4f *points,
01018 int num_points,
01019 SbColor *colors);
01020 void clipPolyLineFar(SoCallbackAction *action,
01021 SbVec4f *points,
01022 int num_points,
01023 SbColor *colors,
01024 int color_flag);
01025 void clipPolyLineXMin(SoCallbackAction *action,
01026 SbVec4f *points,
01027 int num_points,
01028 SbColor *colors,
01029 int color_flag);
01030 void clipPolyLineXMax(SoCallbackAction *action,
01031 SbVec4f *points,
01032 int num_points,
01033 SbColor *colors,
01034 int color_flag);
01035 void clipPolyLineYMin(SoCallbackAction *action,
01036 SbVec4f *points,
01037 int num_points,
01038 SbColor *colors,
01039 int color_flag);
01040 void clipPolyLineYMax(SoCallbackAction *action,
01041 SbVec4f *points,
01042 int num_points,
01043 SbColor *colors,
01044 int color_flag);
01045 void clipPolyMark(SoCallbackAction *action,
01046 SbVec4f *points,
01047 int num_points,
01048 SbColor *colors
01049 #ifndef NO_TGS_OIV
01050 , SoMarkerSet *markerSet = NULL
01051 #endif
01052 );
01053
01054
01055 SoHLHSRVectorize *getHLHSRVectorize() const
01056 { return m_HLHSRVectorize; }
01057 SoHLHSRVectorize *m_HLHSRVectorize;
01058
01059
01060 void projectPoints(SbVec4f *points, int n);
01061
01062
01063
01064 void setProjectionSource(const SbBox2f &projSrc) ;
01065 void setDefaultProjectionSource() ;
01066
01067 void transformPoints(SoCallbackAction *action, SbVec4f *points, int n);
01068 void transformVecMCToVRC(SoCallbackAction *action, SbVec3f &point);
01069 void transformPointsMCToVRC(SoCallbackAction *action,
01070 SbVec4f *points, int n);
01071 void transformPointsVRCToNPC(SoCallbackAction *action,
01072 SbVec4f *points, int n);
01073 SbColor getColor(SoCallbackAction *action,
01074 int index,
01075 SbBool &isFullyTransparent);
01076 SbColor getLightingColor(SoCallbackAction *action,
01077 const SoPrimitiveVertex *vertex,
01078 const SbVec4f &point,
01079 SbBool &isFullyTransparent);
01080 void computeLightList(SoState *state);
01081 void deleteLightsList();
01082 float getAttenuationFactor(const SoCallbackAction *action,
01083 const SbVec3f &lightLocation,
01084 const SbVec3f &vertexPoint);
01085
01086 float getNormalizedWidth();
01087 float getNormalizedHeight();
01088 float computeFontSizeAngleViewing(SoCallbackAction *action,
01089 float fontSize, float &angle);
01090
01091
01092 void setViewportRegion(SoCallbackAction *action);
01093 void setViewportRegion(const SbViewportRegion &vp)
01094 { m_viewportRegion = vp ; }
01095
01096
01097 static float unitsToMillimeters(float w, DimensionUnit u);
01098 static float millimetersToUnits(float w, DimensionUnit u);
01099
01100
01101 static void drawTriangleCB(void *object,
01102 SoCallbackAction *action,
01103 SoPrimitiveVertex *v1,
01104 SoPrimitiveVertex *v2,
01105 SoPrimitiveVertex *v3);
01106 static void drawLineSegmentCB(void *object,
01107 SoCallbackAction *action,
01108 SoPrimitiveVertex *v1,
01109 SoPrimitiveVertex *v2);
01110 static void drawPointCB(void *object,
01111 SoCallbackAction *action,
01112 SoPrimitiveVertex *v);
01113 static SoCallbackAction::Response drawText2CB(void *object,
01114 SoCallbackAction *action,
01115 const SoNode *node);
01116 static SoCallbackAction::Response drawText3CB(void *object,
01117 SoCallbackAction *action,
01118 const SoNode *node);
01119 static SoCallbackAction::Response drawImageCB(void *object,
01120 SoCallbackAction *action,
01121 const SoNode *node);
01122 static SoCallbackAction::Response sendPointsCB(void *object,
01123 SoCallbackAction *action,
01124 const SoNode *node);
01125 static SoCallbackAction::Response drawAnnoText3CB(void *object,
01126 SoCallbackAction *action,
01127 const SoNode *node);
01128 static SoCallbackAction::Response endDrawAnnoText3CB(void *,
01129 SoCallbackAction *,
01130 const SoNode *);
01131 static SoCallbackAction::Response cameraCB(void *object,
01132 SoCallbackAction *action,
01133 const SoNode *node);
01134 static SoCallbackAction::Response storeAnnotationCB(void *object,
01135 SoCallbackAction *action,
01136 const SoNode *node);
01137
01138
01139 void addDelayedPath(SoPath *path);
01140 void renderDelayedPaths();
01141
01142
01143
01144 float m_shiftX, m_shiftY;
01145 Orientation m_orientation;
01146
01147 float m_width, m_height;
01148
01149
01150 SbViewportRegion m_viewportRegion;
01151
01152 ColorTranslationMethod m_colorTranslationMethod;
01153
01154 float *m_pensWidth;
01155 SbBool m_priority;
01156
01157 int m_numAlloc;
01158 int m_numVertices;
01159 SbVec4f *m_pointList;
01160 SbColor *m_colorList;
01161 HLHSRMode m_HLHSRMode;
01162 float m_HLHSRRasterQuality ;
01163 SbBool m_HLHSRRasterCaching ;
01164 unsigned short m_HLHSRRasterTileSize ;
01165 SbBool m_isAnnoText3Drawn;
01166
01167
01168 SoNodeList m_lightNodesList;
01169 SbPList m_lightsList;
01170 SbBool m_isLightingEnabled;
01171
01172
01173 ShadeModel m_shadeModel ;
01174
01175
01176 float m_polyOffset;
01177 float m_lineOffset;
01178 float m_markOffset;
01179
01180
01181
01182 SbBox2f m_projSrc ;
01183
01184
01185 SoPathList m_delayedPaths;
01186
01187
01188 friend class SoHLHSRVectorize;
01189 friend class SoHLHSRImageVectorizer;
01190 };
01191
01201 class SoVectorOutput
01202 {
01203
01204 public:
01205
01209 SoVectorOutput();
01210
01214 virtual ~SoVectorOutput();
01215
01216 public:
01217
01221 virtual void setFilePointer(FILE *newFP);
01222
01227 virtual FILE *getFilePointer();
01228
01235 SoNONUNICODE virtual SbBool openFile(const char *file_name);
01236
01241 virtual SbBool openFile( const SbString& file_name );
01242
01246 virtual void closeFile();
01247
01248 private:
01249
01250 FILE *m_out_file;
01251 };
01252
01253 #endif //__SO_VECTORIZE_ACTION_
01254
01255