[prev in list] [next in list] [prev in thread] [next in thread] 

List:       kde-edu-devel
Subject:    [kde-edu]:  Kig exporters: fix for rational bezier curves
From:       Raoul <raoulb () bluewin ! ch>
Date:       2011-03-30 15:57:46
Message-ID: 20110330175746.57c6e53a () pega ! pega
[Download RAW message or body]

Hi,


In a recent mail I wrote:

> > And the rational bezier cuves do crash Kig when exporting
> > to PSTricks, pgf/Tikz and Asy. But we can export to images
> > and svg.

Today I debugged this and found what I think is the reason.
Although I'm no expert on such things it seems to me the cause
is an endless call loop in the following two code parts:

bezier_imp.cc:502:

void RationalBezierImp::visit( ObjectImpVisitor* vtor ) const
{
  vtor->visit( this );
}

And object_imp.cc:83

void ObjectImpVisitor::visit( const ObjectImp* imp )
{
  imp->visit( this );
}

The generic visit( const ObjectImp* imp ) is called because we
have no specialization for RationalBezierImp Objects. I don't
know why the generic function should call again imp->visit( this ) ...?

If I add this specialized function the issue is fixed. The patch
attached does this and overwrites the function for Asy/TikZ and PS
exporters. Thus we can now export rational bezier curves :-)

However the issue of course remains for other object types
where there is no suitable visit function in the visitor.
(I did not check if there are any more issues.)


I included a second minor fix allowing the PSTricks exporter to
export bezier curves. At the moment it just exports the nodes.

All these implementations for rational bezier curves rely on the
plotGenericCurve function which sometimes does a questionable job.
As I noted in the comments we should improve this later. But I
have to look up how to compute rational bezier curves with the
given functionality of asy/pgf/PS.


I also attached several examples if you are interested.
Sorry for the big files.


-- Raoul
[Attachment #3 (text/x-patch)]

Index: objects/bezier_type.h
===================================================================
--- objects/bezier_type.h	(revision 1226563)
+++ objects/bezier_type.h	(working copy)
@@ -131,7 +131,7 @@
 };
 
 /**
- * Bézier curve of degree n
+ * Rational Bézier curve of degree n
  */
 class RationalBezierCurveType
   : public ObjectType
Index: objects/object_imp.h
===================================================================
--- objects/object_imp.h	(revision 1226563)
+++ objects/object_imp.h	(working copy)
@@ -43,6 +43,7 @@
 class ClosedPolygonalImp;
 class OpenPolygonalImp;
 class BezierImp;
+class RationalBezierImp;
 
 /**
  * \internal This is some OO magic commonly referred to as "double
@@ -80,6 +81,7 @@
   virtual void visit( const ClosedPolygonalImp* imp );
   virtual void visit( const OpenPolygonalImp* imp );
   virtual void visit( const BezierImp* imp );
+  virtual void visit( const RationalBezierImp* imp );
 };
 
 typedef unsigned int uint;
Index: objects/object_imp.cc
===================================================================
--- objects/object_imp.cc	(revision 1226563)
+++ objects/object_imp.cc	(working copy)
@@ -167,6 +167,10 @@
 {
 }
 
+void ObjectImpVisitor::visit( const RationalBezierImp* )
+{
+}
+
 ObjectImpVisitor::~ObjectImpVisitor()
 {
 
Index: filters/asyexporterimpvisitor.h
===================================================================
--- filters/asyexporterimpvisitor.h	(revision 1226563)
+++ filters/asyexporterimpvisitor.h	(working copy)
@@ -72,6 +72,7 @@
   void visit( const ClosedPolygonalImp* imp );
   void visit( const OpenPolygonalImp* imp );
   void visit ( const BezierImp* imp );
+  void visit ( const RationalBezierImp* imp );
 
   double unit;
 
Index: filters/asyexporterimpvisitor.cc
===================================================================
--- filters/asyexporterimpvisitor.cc	(revision 1226563)
+++ filters/asyexporterimpvisitor.cc	(working copy)
@@ -542,9 +542,14 @@
             << " );";
     newLine();
     break;
-// TODO: Rational bezier curves
   default:
     plotGenericCurve ( imp );
     break;
   }
 }
+
+
+void AsyExporterImpVisitor::visit ( const RationalBezierImp* imp )
+{
+  plotGenericCurve ( imp );
+}
\ No newline at end of file
Index: filters/latexexporter.cc
===================================================================
--- filters/latexexporter.cc	(revision 1226563)
+++ filters/latexexporter.cc	(working copy)
@@ -116,7 +116,9 @@
     void visit( const FilledPolygonImp* imp );
     void visit( const ClosedPolygonalImp* imp );
     void visit( const OpenPolygonalImp* imp );
-
+    void visit( const BezierImp* imp );
+    void visit( const RationalBezierImp* imp );
+    
     double unit;
 
 private:
@@ -515,6 +517,19 @@
     newLine();
 }
 
+// TODO: Just a quick fix, improve when reviewing PSTricks exporter
+void PSTricksExportImpVisitor::visit(const BezierImp* imp)
+{
+  plotGenericCurve(imp);
+}
+
+// TODO: Just a quick fix, improve when reviewing PSTricks exporter
+void PSTricksExportImpVisitor::visit(const RationalBezierImp* imp)
+{
+  plotGenericCurve(imp);
+}
+
+
 class TikZExportImpVisitor
             : public ObjectImpVisitor
 {
@@ -548,6 +563,7 @@
     void visit( const ClosedPolygonalImp* imp );
     void visit( const OpenPolygonalImp* imp );
     void visit( const BezierImp* imp);
+    void visit( const RationalBezierImp* imp);
 
     double unit;
 
@@ -963,6 +979,13 @@
     }
 }
 
+// TODO: Just a quick fix, improve when reviewing TikZ exporter
+void TikZExportImpVisitor::visit(const RationalBezierImp* imp)
+{
+  plotGenericCurve(imp);
+}
+
+
 void LatexExporter::run( const KigPart& doc, KigWidget& w )
 {
     KigFileDialog* kfd = new KigFileDialog(

[Attachment #4 (application/x-gzip)]

_______________________________________________
kde-edu mailing list
kde-edu@mail.kde.org
https://mail.kde.org/mailman/listinfo/kde-edu


[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic