Spline weights are not read from DXF file.

If you are having problems with dxflib, post here. Please report bugs here.

Moderator: andrew

Post Reply
beding
Newbie Member
Posts: 5
Joined: Mon Nov 08, 2010 12:53 pm

Spline weights are not read from DXF file.

Post by beding » Wed Nov 09, 2011 6:33 pm

Why are they not read?
Can you tell me ho to add code to read the weights?
Regards,
Bert

User avatar
andrew
Site Admin
Posts: 9019
Joined: Fri Mar 30, 2007 6:07 am

Post by andrew » Sun Nov 27, 2011 11:04 pm

This patch should do it:

Code: Select all

Index: dl_dxf.cpp
--- dl_dxf.cpp	(revision 19810)
+++ dl_dxf.cpp	(working copy)
@@ -56,9 +56,11 @@
     maxKnots = 0;
     knotIndex = 0;
 
+    weights = NULL;
     controlPoints = NULL;
     maxControlPoints = 0;
     controlPointIndex = 0;
+    weightIndex = 0;
 
     leaderVertices = NULL;
     maxLeaderVertices = 0;
@@ -88,6 +90,9 @@
     if (controlPoints!=NULL) {
         delete[] controlPoints;
     }
+    if (weights!=NULL) {
+        delete[] weights;
+    }
     if (leaderVertices!=NULL) {
         delete[] leaderVertices;
     }
@@ -941,7 +946,8 @@
     for (i=0; i<maxControlPoints; i++) {
         DL_ControlPointData d(controlPoints[i*3],
                               controlPoints[i*3+1],
-                              controlPoints[i*3+2]);
+                              controlPoints[i*3+2], 
+                              weights[i]);
 
         creationInterface->addControlPoint(d);
     }
@@ -1218,21 +1224,27 @@
         return true;
     }
 
-    // Allocate Spline control points (group code 73):
+    // Allocate Spline control points / weights (group code 73):
     else if (groupCode==73) {
         maxControlPoints = toInt(groupValue);
         if (maxControlPoints>0) {
             if (controlPoints!=NULL) {
                 delete[] controlPoints;
             }
+            if (weights!=NULL) {
+                delete[] weights;
+            }
             controlPoints = new double[3*maxControlPoints];
+            weights = new double[maxControlPoints];
             for (int i=0; i<maxControlPoints; ++i) {
                 controlPoints[i*3] = 0.0;
                 controlPoints[i*3+1] = 0.0;
                 controlPoints[i*3+2] = 0.0;
+                weights[i] = 1.0;
             }
         }
         controlPointIndex=-1;
+        weightIndex=-1;
         return true;
     }
 
@@ -1259,6 +1271,19 @@
         }
         return true;
     }
+
+    // Compute spline weights (group code 41)
+    else if (groupCode==41) {
+
+        if (weightIndex<maxControlPoints-1) {
+            weightIndex++;
+        }
+
+        if (weightIndex>=0 && weightIndex<maxControlPoints) {
+            weights[weightIndex] = toReal(groupValue);
+        }
+        return true;
+    }
     return false;
 }
 
Index: dl_dxf.h
--- dl_dxf.h	(revision 19810)
+++ dl_dxf.h	(working copy)
@@ -379,9 +379,11 @@
     int maxKnots;
     int knotIndex;
 	
+    double* weights;
     double* controlPoints;
     int maxControlPoints;
     int controlPointIndex;
+    int weightIndex;
 
     double* leaderVertices;
     int maxLeaderVertices;
Index: dl_entities.h
--- dl_entities.h	(revision 19810)
+++ dl_entities.h	(working copy)
@@ -442,10 +442,11 @@
      * Constructor.
      * Parameters: see member variables.
      */
-    DL_ControlPointData(double px, double py, double pz) {
+    DL_ControlPointData(double px, double py, double pz, double weight) {
         x = px;
         y = py;
         z = pz;
+        w = weight;
     }
 
     /*! X coordinate of the control point. */
@@ -454,6 +455,8 @@
     double y;
     /*! Z coordinate of the control point. */
     double z;
+    /*! Weight of control point. */
+    double w;
 };

Post Reply

Return to “dxflib Troubleshooting and Problems”