- Timestamp:
- 03/21/12 18:36:20 (14 months ago)
- Files:
-
- 1 modified
Legend:
- Unmodified
- Added
- Removed
-
OpenSceneGraph/trunk/src/osgPlugins/dxf/DXFWriterNodeVisitor.h
r13017 r13041 9 9 * texture coord arrays, bug fixes, and support for texture mapping. 10 10 * 11 * Writing support added 2007 by Stephan Huber, http://digitalmind.de, 11 * Writing support added 2007 by Stephan Huber, http://digitalmind.de, 12 12 * some ideas taken from the dae-plugin 13 13 * 14 * The Open Scene Graph (OSG) is a cross platform C++/OpenGL library for 15 * real-time rendering of large 3D photo-realistic models. 14 * The Open Scene Graph (OSG) is a cross platform C++/OpenGL library for 15 * real-time rendering of large 3D photo-realistic models. 16 16 * The OSG homepage is http://www.openscenegraph.org/ 17 17 */ 18 18 19 19 #ifndef DXF_WRITER_NODE_VISITOR_HEADER__ 20 20 #define DXF_WRITER_NODE_VISITOR_HEADER__ … … 59 59 { 60 60 public: 61 AcadColor() 61 AcadColor() 62 62 { 63 63 int index=10; … … 94 94 protected: 95 95 // returns hue as an angle in range 0-360, saturation and value as 0-1 96 void hsv(unsigned int rgb,float &hue,float &sat,float &value) 96 void hsv(unsigned int rgb,float &hue,float &sat,float &value) 97 97 { 98 98 int red = rgb>>16; … … 103 103 104 104 value = (float)H/255.0f; // note hsv and hsl define v differently! 105 sat=(float)(H-L)/(float)H; 105 sat=(float)(H-L)/(float)H; 106 106 107 107 if (H==L) { 108 hue=0.0; 108 hue=0.0; 109 109 }else if (H==red) { 110 110 hue=360.0 + (60.0 * (float)(green-blue)/(float)(H-L)); … … 115 115 hue=240.0 + (60.0 * (float)(red-green)/(float)(H-L)); 116 116 } else { 117 hue = 0.0; 118 } 117 hue = 0.0; 118 } 119 119 } 120 120 … … 127 127 hsv(rgb,h,s,v); 128 128 129 // aci index format is 129 // aci index format is 130 130 // last digit odd = 50% sat, even=100% 131 131 // last digit 0,1 = 100% value, 2,3=80%, 4,5=60% 6,7=50%, 8,9=30% 132 // first two sigits are hue angle /1.5 but count starts at 10, first 9 values are dummy named colours 132 // first two sigits are hue angle /1.5 but count starts at 10, first 9 values are dummy named colours 133 133 int aci=10 + (int)(h/1.5); 134 134 aci -= (aci%10); // ensure last digit is zero 135 135 136 136 if ( v < 0.3 ) { 137 137 aci += 9; … … 153 153 } 154 154 155 155 156 156 157 157 protected: 158 158 159 159 typedef std::map<unsigned int, unsigned char> ColorMap; 160 160 ColorMap _indexColors; // maps RGB to autocad index colour … … 165 165 166 166 public: 167 DXFWriterNodeVisitor(std::ostream& fout) : 168 osg::NodeVisitor(osg::NodeVisitor::TRAVERSE_ALL_CHILDREN), 169 _fout(fout), 167 DXFWriterNodeVisitor(std::ostream& fout) : 168 osg::NodeVisitor(osg::NodeVisitor::TRAVERSE_ALL_CHILDREN), 169 _fout(fout), 170 170 _currentStateSet(new osg::StateSet()), 171 171 _firstPass(true), 172 172 _writeTriangleAs3DFace(true) 173 173 { 174 175 176 } 177 178 static unsigned int getNodeRGB(osg::Geometry *geo,unsigned int index=0) 174 175 176 } 177 178 static unsigned int getNodeRGB(osg::Geometry *geo,unsigned int index=0) 179 179 { 180 180 osg::Vec4Array* data=static_cast<osg::Vec4Array*>(geo->getColorArray()); 181 181 if ( data && index<data->size() ) { 182 return (data->at(index).asABGR())>>8; 182 return (data->at(index).asABGR())>>8; 183 183 } 184 184 return 0; 185 185 } 186 186 187 188 bool writeHeader(const osg::BoundingSphere &bound);// call after first pass to trigger draw pass 187 188 bool writeHeader(const osg::BoundingSphere &bound);// call after first pass to trigger draw pass 189 189 void writeFooter(); 190 190 191 191 void buildColorMap(); 192 192 193 virtual void apply(osg::Geode &node); 194 195 virtual void apply(osg::Group &node) 196 { 193 virtual void apply(osg::Geode &node); 194 195 virtual void apply(osg::Group &node) 196 { 197 197 osg::NodeVisitor::traverse( node ); 198 198 199 199 } 200 200 … … 213 213 // Save our current stateset 214 214 _stateSetStack.push(_currentStateSet.get()); 215 215 216 216 // merge with node stateset 217 217 _currentStateSet = static_cast<osg::StateSet*>(_currentStateSet->clone(osg::CopyOp::SHALLOW_COPY)); 218 _currentStateSet->merge(*ss); 218 _currentStateSet->merge(*ss); 219 219 } 220 220 } … … 229 229 } 230 230 } 231 231 232 232 int getNodeAcadColor(osg::Geometry *geo,int index=0) { return 0;} 233 233 234 234 protected: 235 235 struct CompareStateSet … … 241 241 }; 242 242 243 243 244 244 private: 245 245 246 246 DXFWriterNodeVisitor& operator = (const DXFWriterNodeVisitor&) { return *this; } 247 247 … … 251 251 // second pass - output data 252 252 void processGeometry(osg::Geometry* geo, osg::Matrix& m); 253 253 254 254 255 255 void processArray(osg::Array* array, const Layer& layer,const osg::Matrix& m = osg::Matrix::identity()); 256 256 257 257 void processStateSet(osg::StateSet* stateset); 258 258 259 259 std::string getLayerName(const std::string& defaultValue = ""); 260 260 261 261 typedef std::stack<osg::ref_ptr<osg::StateSet> > StateSetStack; 262 262 … … 270 270 271 271 unsigned int _count; 272 std::vector<Layer> _layers; 272 std::vector<Layer> _layers; 273 273 bool _firstPass; 274 274 Layer _layer; 275 275 276 276 bool _writeTriangleAs3DFace; 277 277 278 278 AcadColor _acadColor; 279 279 280 280 281 281 };
