Changeset 13041 for OpenSceneGraph/trunk/src/osgPlugins/dxf/dxfEntity.cpp
- Timestamp:
- 03/21/12 18:36:20 (14 months ago)
- Files:
-
- 1 modified
Legend:
- Unmodified
- Added
- Removed
-
OpenSceneGraph/trunk/src/osgPlugins/dxf/dxfEntity.cpp
r13035 r13041 1 1 /* dxfReader for OpenSceneGraph Copyright (C) 2005 by GraphArchitecture ( grapharchitecture.com ) 2 2 * Programmed by Paul de Repentigny <pdr@grapharchitecture.com> 3 * 3 * 4 4 * OpenSceneGraph is (C) 2004 Robert Osfield 5 * 5 * 6 6 * This library is provided as-is, without support of any kind. 7 7 * 8 8 * Read DXF docs or OSG docs for any related questions. 9 * 9 * 10 10 * You may contact the author if you have suggestions/corrections/enhancements. 11 11 */ … … 35 35 RegisterEntityProxy<dxfText> g_dxfText; 36 36 37 void 37 void 38 38 dxfBasicEntity::assign(dxfFile* , codeValue& cv) 39 39 { … … 71 71 _vertices[cv._groupCode - 30].z() = d; 72 72 break; 73 73 74 74 default: 75 75 dxfBasicEntity::assign(dxf, cv); … … 104 104 double d = cv._double; 105 105 // 2005.12.13 pdr: learned today that negative indices mean something and were possible 106 106 107 107 int s = cv._int; // 2005.12.13 pdr: group codes [70,78] now signed int. 108 108 if ( s < 0 ) s = -s; … … 129 129 _indice4 = s; 130 130 break; 131 131 132 132 default: 133 133 dxfBasicEntity::assign(dxf, cv); … … 180 180 181 181 if (_useAccuracy) { 182 // we generate points on a polyline where each point lies on the arc, thus the maximum error occurs at the midpoint of each line segment where it lies furthest inside the arc 183 // If we divide the segment in half and connect the bisection point to the arc's center, we have two rightangled triangles with 182 // we generate points on a polyline where each point lies on the arc, thus the maximum error occurs at the midpoint of each line segment where it lies furthest inside the arc 183 // If we divide the segment in half and connect the bisection point to the arc's center, we have two rightangled triangles with 184 184 // one side=r-maxError, hypotenuse=r, and internal angle at center is half the angle we will step with: 185 double maxError=min(_maxError,_radius); // Avoid offending acos() in the edge case where allowable deviation is greater than radius. 185 double maxError=min(_maxError,_radius); // Avoid offending acos() in the edge case where allowable deviation is greater than radius. 186 186 double newtheta=acos( (_radius-maxError) / _radius); 187 newtheta=osg::RadiansToDegrees(newtheta)*2.0; 188 187 newtheta=osg::RadiansToDegrees(newtheta)*2.0; 188 189 189 // Option to only use the new accuracy code when it would improve on the accuracy of the old method 190 190 if (_improveAccuracyOnly) { … … 193 193 theta=newtheta; 194 194 } 195 } 195 } 196 196 theta=osg::DegreesToRadians(theta); 197 197 198 198 // We create an anglestep<=theta so that the line's points are evenly distributed around the circle 199 199 unsigned int numsteps=static_cast<unsigned int>(floor(osg::PI*2/theta)); 200 if (numsteps<3) numsteps=3; // Sanity check: minimal representation of a circle is a tri 200 if (numsteps<3) numsteps=3; // Sanity check: minimal representation of a circle is a tri 201 201 double anglestep=osg::PI*2/numsteps; 202 202 … … 210 210 } 211 211 212 sc->addLineStrip(getLayer(), _color, vlist); // Should really add LineLoop implementation and save a vertex 212 sc->addLineStrip(getLayer(), _color, vlist); // Should really add LineLoop implementation and save a vertex 213 213 sc->ocs_clear(); 214 214 } … … 274 274 275 275 if (_useAccuracy) { 276 // we generate points on a polyline where each point lies on the arc, thus the maximum error occurs at the midpoint of each line segment where it lies furthest inside the arc 277 // If we divide the segment in half and connect the bisection point to the arc's center, we have two rightangled triangles with 276 // we generate points on a polyline where each point lies on the arc, thus the maximum error occurs at the midpoint of each line segment where it lies furthest inside the arc 277 // If we divide the segment in half and connect the bisection point to the arc's center, we have two rightangled triangles with 278 278 // one side=r-maxError, hypotenuse=r, and internal angle at center is half the angle we will step with: 279 double maxError=min(_maxError,_radius); // Avoid offending acos() in the edge case where allowable deviation is greater than radius. 279 double maxError=min(_maxError,_radius); // Avoid offending acos() in the edge case where allowable deviation is greater than radius. 280 280 double newtheta=acos( (_radius-maxError) / _radius); 281 newtheta=osg::RadiansToDegrees(newtheta)*2.0; 281 newtheta=osg::RadiansToDegrees(newtheta)*2.0; 282 282 //cout<<"r="<<_radius<<" _me="<<_maxError<<" (_radius-_maxError)="<<(_radius-_maxError)<<" newtheta="<<newtheta<<endl; 283 283 // Option to only use the new accuracy code when it would improve on the accuracy of the old method … … 287 287 theta=newtheta; 288 288 } 289 } 289 } 290 290 291 291 double angle_step = DegreesToRadians(end - start); 292 int numsteps = (int)((end - start)/theta); 292 int numsteps = (int)((end - start)/theta); 293 293 //cout<<"arc theta="<<osg::RadiansToDegrees(theta)<<" end="<<end<<" start="<<start<<" numsteps="<<numsteps<<" e-s/theta="<<((end-start)/theta)<<" end-start="<<(end-start)<<endl; 294 294 if (numsteps * theta < (end - start)) numsteps++; … … 298 298 start = DegreesToRadians((-_endAngle)+90.0); 299 299 double angle1 = start; 300 300 301 301 Vec3d a = _center; 302 302 Vec3d b; 303 303 304 for (int r = 0; r <= numsteps; r++) 304 for (int r = 0; r <= numsteps; r++) 305 305 { 306 306 b = a + Vec3d(_radius * (double) sin(angle1), _radius * (double) cos(angle1), 0); … … 394 394 } 395 395 396 void 396 void 397 397 dxfPolyline::assign(dxfFile* dxf, codeValue& cv) 398 398 { … … 406 406 _currentVertex->assign(dxf, cv); 407 407 408 if ((_flag & 64 /*i.e. polymesh*/) && 409 (cv._groupCode == 70 /*i.e. vertex flag*/) && 408 if ((_flag & 64 /*i.e. polymesh*/) && 409 (cv._groupCode == 70 /*i.e. vertex flag*/) && 410 410 (cv._int & 128 /*i.e. vertex is actually a face*/)) 411 411 _indices.push_back(_currentVertex); // Add the index only if _currentvertex is actually an index … … 428 428 // Meaningful only when _surfacetype == 6, don' trust it for polymeshes. 429 429 // From the docs : 430 // "The 71 group specifies the number of vertices in the mesh, and the 72 group 431 // specifies the number of faces. Although these counts are correct for all meshes 432 // created with the PFACE command, applications are not required to place correct 430 // "The 71 group specifies the number of vertices in the mesh, and the 72 group 431 // specifies the number of faces. Although these counts are correct for all meshes 432 // created with the PFACE command, applications are not required to place correct 433 433 // values in these fields.)" 434 434 // Amusing isn't it ? … … 438 438 // Meaningful only when _surfacetype == 6, don' trust it for polymeshes. 439 439 // From the docs : 440 // "The 71 group specifies the number of vertices in the mesh, and the 72 group 441 // specifies the number of faces. Although these counts are correct for all meshes 442 // created with the PFACE command, applications are not required to place correct 440 // "The 71 group specifies the number of vertices in the mesh, and the 72 group 441 // specifies the number of faces. Although these counts are correct for all meshes 442 // created with the PFACE command, applications are not required to place correct 443 443 // values in these fields.)" 444 444 // Amusing isn't it ? … … 488 488 unsigned int ncount; 489 489 unsigned int mcount; 490 if (_surfacetype == 6) { 490 if (_surfacetype == 6) { 491 491 // I dont have examples of type 5 and 8, but they may be the same as 6 492 492 mcount = _mdensity; 493 493 ncount = _ndensity; 494 } else { 494 } else { 495 495 mcount = _mcount; 496 496 ncount = _ncount; … … 619 619 sc->addTriangles(getLayer(), _color, vlist, invert_order); 620 620 621 } else if (_flag & 64) { 621 } else if (_flag & 64) { 622 622 unsigned short _facetype = 3; 623 623 … … 679 679 } 680 680 681 void 681 void 682 682 dxfLWPolyline::assign(dxfFile* dxf, codeValue& cv) 683 683 { … … 797 797 // and push it back after we fill our context 798 798 // This is a snapshot in time. I will rewrite all this to be cleaner, 799 // but for now, it seems working fine 799 // but for now, it seems working fine 800 800 // (with the files I have, the results are equal to Voloview, 801 801 // and better than Deep Exploration and Lightwave). 802 802 803 803 // sanity check (useful when no block remains after all unsupported entities have been filtered out) 804 804 if (!_block) … … 840 840 } 841 841 842 void 842 void 843 843 dxfText::assign(dxfFile* dxf, codeValue& cv) 844 844 { … … 913 913 _text->setCharacterSize( _height, 1.0/_xscale ); 914 914 _text->setFont("arial.ttf"); 915 915 916 916 Quat qr( DegreesToRadians(_rotation), Z_AXIS ); 917 917 918 918 if ( _flags & 2 ) qr = Quat( PI, Y_AXIS ) * qr; 919 919 if ( _flags & 4 ) qr = Quat( PI, X_AXIS ) * qr; 920 920 921 921 _text->setAxisAlignment(osgText::Text::USER_DEFINED_ROTATION); 922 922 _text->setRotation(qr); 923 923 924 924 if ( _hjustify != 0 || _vjustify !=0 ) _point1 = _point2; 925 925 926 926 switch (_vjustify) { 927 927 case 3: … … 974 974 break; 975 975 } 976 976 977 977 _text->setAlignment(align); 978 978 979 979 sc->addText(getLayer(), _color, _point1, _text.get()); 980 980 sc->ocs_clear(); … … 983 983 984 984 // static 985 void 985 void 986 986 dxfEntity::registerEntity(dxfBasicEntity* entity) 987 987 { … … 990 990 991 991 // static 992 void 992 void 993 993 dxfEntity::unregisterEntity(dxfBasicEntity* entity) 994 994 { … … 1007 1007 } 1008 1008 1009 void 1009 void 1010 1010 dxfEntity::assign(dxfFile* dxf, codeValue& cv) 1011 1011 { … … 1014 1014 // The funny thing here. Group code 66 has been called 'obsoleted' 1015 1015 // for a POLYLINE. But not for an INSERT. Moreover, a TABLE 1016 // can have a 66 for... an obscure bottom cell color value. 1016 // can have a 66 for... an obscure bottom cell color value. 1017 1017 // I decided to rely on the presence of the 66 code for 1018 1018 // the POLYLINE. If you find a better alternative,
