From 1ea6bdac0eae394bd3dd628346bb6021eaba582f Mon Sep 17 00:00:00 2001
From: Marco Biasini <marco.biasini@unibas.ch>
Date: Tue, 11 Jan 2011 15:53:21 +0100
Subject: [PATCH] As discussed with Ansgar, revert recent changes to anti-twist
 code

This reverts commits f4caabref and f232e60c
---
 modules/base/src/profile.cc              |  2 +-
 modules/gfx/src/impl/cartoon_renderer.cc | 27 ++-----
 modules/gfx/src/impl/entity_detail.cc    | 98 ------------------------
 modules/gfx/src/vertex_array.cc          | 25 ++----
 modules/gfx/src/vertex_array.hh          |  2 -
 5 files changed, 14 insertions(+), 140 deletions(-)

diff --git a/modules/base/src/profile.cc b/modules/base/src/profile.cc
index 73b354041..e1dc2d246 100644
--- a/modules/base/src/profile.cc
+++ b/modules/base/src/profile.cc
@@ -42,7 +42,7 @@ Profile::~Profile()
 {
   struct timeval end;
   gettimeofday(&end,NULL);
-  std::cerr << msg_ << " finished in " <<delta_time(start_, end) 
+  std::cout << msg_ << " finished in " <<delta_time(start_, end) 
             << "s" << std::endl;
 }
 
diff --git a/modules/gfx/src/impl/cartoon_renderer.cc b/modules/gfx/src/impl/cartoon_renderer.cc
index 019dbd49b..b52d496f0 100644
--- a/modules/gfx/src/impl/cartoon_renderer.cc
+++ b/modules/gfx/src/impl/cartoon_renderer.cc
@@ -31,8 +31,6 @@
 #include <ost/gfx/entity.hh>
 #include <ost/gfx/impl/tabulated_trig.hh>
 
-#include <ost/profile.hh>
-
 namespace ost {
 
 namespace gfx {
@@ -58,7 +56,6 @@ void CartoonRenderer::PrepareRendering(const BackboneTrace& subset,
                                        SplineEntryListList& spline_list_list,
                                        bool)
 {
-  Profile p0("CartoonRenderer::PrepareRendering(s,va,sll,f)");
   if(options_==NULL) {
     LOG_DEBUG("CartoonRenderer: NULL options, not creating objects");
   }
@@ -124,7 +121,6 @@ void CartoonRenderer::PrepareRendering(const BackboneTrace& subset,
 
 void CartoonRenderer::PrepareRendering()
 {
-  Profile p0("CartoonRenderer::PrepareRendering()");
   TraceRendererBase::PrepareRendering();
   if(state_>0) {
     va_.Clear();
@@ -386,7 +382,6 @@ void CartoonRenderer::RebuildSplineObj(IndexedVertexArray& va,
                                        const SplineEntryListList& spline_list_list,
                                        bool is_sel)
 {
-  Profile p0("CartoonRenderer::RebuildSplineObj");
   LOG_DEBUG("CartoonRenderer: starting profile assembly");
   unsigned int detail = std::min(MAX_ARC_DETAIL,
                                  std::max(options_->GetArcDetail(),
@@ -546,14 +541,12 @@ TraceProfile CartoonRenderer::TransformAndAddProfile(const std::vector<TraceProf
 
 namespace {
 
-  float spread(Real* v1, Real* v2, Real* v3, Real* v4)
+  float spread(const geom::Vec3& v1, geom::Vec3& v2, geom::Vec3& v3, geom::Vec3& v4)
   {
-    geom::Vec3 a(v3[0]-v1[0],v3[1]-v1[1],v3[2]-v1[2]);
-    geom::Vec3 b(v2[0]-v1[0],v2[1]-v1[1],v2[2]-v1[2]);
-    geom::Vec3 c(v3[0]-v4[0],v3[1]-v4[1],v3[2]-v4[2]);
-    geom::Vec3 d(v2[0]-v4[0],v2[1]-v4[1],v2[2]-v4[2]);
-    return geom::Dot(geom::Normalize(geom::Cross(a,b)),geom::Normalize(geom::Cross(c,d)));
+    return geom::Dot(geom::Normalize(geom::Cross(geom::Normalize(v3-v1),geom::Normalize(v2-v1))),
+		     geom::Normalize(geom::Cross(geom::Normalize(v3-v4),geom::Normalize(v2-v4))));
   }
+
 }
 
 void CartoonRenderer::AssembleProfile(const TraceProfile& prof1,
@@ -570,19 +563,18 @@ void CartoonRenderer::AssembleProfile(const TraceProfile& prof1,
   */
   size_t size=prof1.size()-1;
 
-#if 0
   // first get the best correction offset
   float accum[]={0.0,0.0,0.0,0.0,0.0};
   for(size_t i=0;i<size;++i) {
     int i1=(i+0)%(size);
     int i2=(i+1)%(size);
-    Real* v1=va.GetVertP(prof1[i1].id);
-    Real* v2=va.GetVertP(prof1[i2].id);
+    geom::Vec3 v1=va.GetVert(prof1[i1].id);
+    geom::Vec3 v2=va.GetVert(prof1[i2].id);
     for(int k=-2;k<=2;++k) {
       int i3=(i+k+0+size)%(size);
       int i4=(i+k+1+size)%(size);
-      Real* v3=va.GetVertP(prof2[i3].id);
-      Real* v4=va.GetVertP(prof2[i4].id);
+      geom::Vec3 v3=va.GetVert(prof2[i3].id);
+      geom::Vec3 v4=va.GetVert(prof2[i4].id);
       accum[k+2]+=spread(v1,v2,v3,v4);
     }
   }
@@ -596,9 +588,6 @@ void CartoonRenderer::AssembleProfile(const TraceProfile& prof1,
     }
   }
   best_off=(best_off+(size))%(size);
-#else
-  int best_off=0;
-#endif
 
   // now assemble the triangles
   for(unsigned int i1=0;i1<size;++i1) {
diff --git a/modules/gfx/src/impl/entity_detail.cc b/modules/gfx/src/impl/entity_detail.cc
index 94981a4fb..40ba73518 100644
--- a/modules/gfx/src/impl/entity_detail.cc
+++ b/modules/gfx/src/impl/entity_detail.cc
@@ -304,102 +304,6 @@ SplineEntryList Spline::Generate(const SplineEntryList& entry_list, int nsub, ui
   SPLINE_ENTRY_INTERPOLATE(rad);
 
   LOG_DEBUG("SplineGenerate: assigning direction and normal components");
-
-#if 0
-  std::vector<Quat> quats(size+3);
-
-  Vec3 prevn;
-  for(int c=0;c<size;++c) {
-    Vec3 d1,d2;
-    if(c==0) {
-      d1=Normalize(entry_list.at(c).position-entry_list.at(c+1).position);
-      d2=Normalize(entry_list.at(c+1).position-entry_list.at(c+2).position);
-    } else if(c==size-1) {
-      d1=Normalize(entry_list.at(c-2).position-entry_list.at(c-1).position);
-      d2=Normalize(entry_list.at(c-1).position-entry_list.at(c).position);
-    } else {
-      d1=Normalize(entry_list.at(c-1).position-entry_list.at(c).position);
-      d2=Normalize(entry_list.at(c).position-entry_list.at(c+1).position);
-    }
-    Vec3 d=d2;
-    Vec3 n=Normalize(Cross(d1,d2));
-    //Vec3 n=entry_list.at(c).v1;
-    Vec3 o = Normalize(Cross(d,n));
-
-    if(c>0) {
-      if(Dot(Normalize(Cross(d,prevn)),Normalize(Cross(d,n)))<0.0) {
-        n=-n;
-        o=-o;
-      }
-    }
-    prevn=n;
-
-    //n = Normalize(Cross(o,d));
-    Quat q(Mat3(d[0],n[0],o[0],
-                d[1],n[1],o[1],
-                d[2],n[2],o[2]));
-    quats[c+1]=q;
-  }
-  quats.at(0)=quats.at(1);
-  quats.at(size)=quats.at(size-1);
-  quats.at(size+1)=quats.at(size-1);
-  
-  std::vector<Quat> squats(size*nsub);
-  // now for the quaternion interpolation, using squad
-  for(int c=0;c<size;++c) {
-    Quat q0=quats.at(c+0);
-    Quat q1=quats.at(c+1);
-    Quat q2=quats.at(c+2);
-    Quat q3=quats.at(c+3);
-
-    Quat s1=q1*Exp(-0.25*Log(Inv(q1)*q2)+Log(Inv(q1)*q0));
-    Quat s2=q2*Exp(-0.25*Log(Inv(q2)*q3)+Log(Inv(q2)*q1));
-
-    for(int d=0;d<nsub;++d) {
-      float u=static_cast<float>(d)*i_nsub;
-      squats.at(c*nsub+d) = Slerp(Slerp(q1,q2,u),Slerp(s1,s2,u),2.0*u*(1.0-u));
-    }
-  }
-
-  assert(sublist.size()<=squats.size());
-
-  for(unsigned int i=0;i<sublist.size();++i) {
-    Mat3 m=squats[i].ToRotationMatrix();
-    sublist.at(i).direction=Normalize(Vec3(m(0,0),m(1,0),m(2,0)));
-    sublist.at(i).normal=Normalize(Vec3(m(0,1),m(1,1),m(2,1)));
-    sublist.at(i).v2=Normalize(Vec3(m(0,2),m(1,2),m(2,2)));
-  }
-
-  std::vector<Vec3> nlist(sublist.size());
-  for(uint i=0;i<sublist.size();++i) {
-    Vec3 p0,p1;
-    if(i<sublist.size()-1) {
-      p0 = sublist.at(i).position;
-      p1 = sublist.at(i+1).position;
-    } else {
-      p0 = sublist.at(i-1).position;
-      p1 = sublist.at(i).position;
-    }
-    sublist.at(i).direction=Normalize(p1-p0);
-    Vec3 orth = Normalize(Cross(sublist.at(i).direction,sublist.at(i).normal));
-    nlist[i] = Normalize(Cross(orth,sublist.at(i).direction));
-    sublist.at(i).v2=orth;
-    if(i>0) {
-      if(Dot(Normalize(Cross(sublist.at(i).direction,nlist[i-1])),orth)<0.0) {
-        nlist[i]=-nlist[i];
-        sublist.at(i).v2=-sublist.at(i).v2;
-      }
-    }
-  }
-
-  sublist.at(0).normal=nlist[0];
-  sublist.back().normal=nlist.back();
-  for(uint i=1;i<sublist.size()-1;++i) {
-    sublist.at(i).normal=Normalize((nlist[i-1]+nlist[i]+nlist[i+1])/3.0);   
-  }
-
-#else
-
   // assign direction and normal
   // entity trace has the same algorithm
 
@@ -463,8 +367,6 @@ SplineEntryList Spline::Generate(const SplineEntryList& entry_list, int nsub, ui
     sublist.at(i).normal = sublist.at(i).v0;
   }
 
-#endif
-
   LOG_DEBUG("SplineGenerate: assigning non-interpolated entry components");
   // finally the non-interpolated type
   // with some tweaks for proper strand rendering
diff --git a/modules/gfx/src/vertex_array.cc b/modules/gfx/src/vertex_array.cc
index d2acd821d..ce0f4b731 100644
--- a/modules/gfx/src/vertex_array.cc
+++ b/modules/gfx/src/vertex_array.cc
@@ -30,22 +30,17 @@
 #include "scene.hh"
 #include "vertex_array_helper.hh"
 #include "povray.hh"
-#include <ost/profile.hh>
 
 #if OST_SHADER_SUPPORT_ENABLED
 #include "shader.hh"
 #endif
 
 
-#ifdef NDEBUG
-#define VERTEX_ARRAY_CHECK_GL_ERROR(m)
-#else
 #define VERTEX_ARRAY_CHECK_GL_ERROR(m) \
   if((glerr=glGetError())!=0) {  \
     LOG_ERROR("Error during va buffer prep: " << m << " : " << gluErrorString(glerr)); \
     return false; \
   }
-#endif
 
 namespace ost { 
 
@@ -320,12 +315,6 @@ Vec3 IndexedVertexArray::GetVert(VertexID id) const
   return nrvo;
 } 
 
-Real* IndexedVertexArray::GetVertP(VertexID id)
-{
-  if(id>=entry_list_.size()) id=0;
-  return entry_list_[id].v;
-}
-
 void IndexedVertexArray::SetVert(VertexID id, const Vec3& v) 
 {
   if(id>=entry_list_.size()) return;
@@ -399,7 +388,7 @@ void IndexedVertexArray::SetOpacity(float o)
 void IndexedVertexArray::RenderGL() 
 {
   static bool use_buff=false;
-
+  
   if(!initialized_) {
     LOG_DEBUG("initializing vertex array lists");
 #if OST_SHADER_SUPPORT_ENABLED
@@ -1084,14 +1073,10 @@ bool IndexedVertexArray::prep_buff()
 {
   if(Scene::Instance().InOffscreenMode()) return false;
 #if OST_SHADER_SUPPORT_ENABLED
-  static bool init=false;
-  if(!init) {
-    glEnableClientState(GL_VERTEX_ARRAY);
-    glEnableClientState(GL_NORMAL_ARRAY);
-    glEnableClientState(GL_COLOR_ARRAY);
-    glEnableClientState(GL_INDEX_ARRAY);
-    init=true;
-  }
+  glEnableClientState(GL_VERTEX_ARRAY);
+  glEnableClientState(GL_NORMAL_ARRAY);
+  glEnableClientState(GL_COLOR_ARRAY);
+  glEnableClientState(GL_INDEX_ARRAY);
 
   int glerr=glGetError(); // clear error flag
   glBindBuffer(GL_ARRAY_BUFFER, buffer_id_[VA_VERTEX_BUFFER]);
diff --git a/modules/gfx/src/vertex_array.hh b/modules/gfx/src/vertex_array.hh
index ed4cebb2a..3883c2abe 100644
--- a/modules/gfx/src/vertex_array.hh
+++ b/modules/gfx/src/vertex_array.hh
@@ -140,8 +140,6 @@ class DLLEXPORT_OST_GFX IndexedVertexArray {
   geom::Vec3 GetVert(VertexID id) const;
   void SetVert(VertexID id, const geom::Vec3& vert);
 
-  Real* GetVertP(VertexID id);
-
   geom::Vec3 GetNormal(VertexID id) const;
   void SetNormal(VertexID id, const geom::Vec3& norm);
 
-- 
GitLab