Permalink
Browse files

Merge branch 'kbm' of github.com:avik-das/shape-optimization into kbm

Conflicts:
	src/KBMTorus.cpp
	src/KBMTorus.h
	src/SplineCoaster.cpp
  • Loading branch information...
2 parents db0d678 + ee84369 commit 4236bcd9b023a38ca055d069f1e90093723ce0e1 @avik-das committed Mar 7, 2012
Showing with 111 additions and 30 deletions.
  1. +77 −22 src/KBMTorus.cpp
  2. +6 −0 src/KBMTorus.h
  3. +19 −5 src/SplineCoaster.cpp
  4. +1 −0 src/SplineCoaster.h
  5. +7 −2 src/energy.cpp
  6. +1 −1 src/main.cpp
View
@@ -104,6 +104,38 @@ void KBMTorus::dumpPoints() {
leftarm->dumpPoints();
cout << "Right Arm:" << endl;
rghtarm->dumpPoints();
+
+double KBMTorus::getTorTilt() {
+ return tortilt;
+}
+
+void KBMTorus::changeTorTilt(double dtilt) {
+ tortilt += dtilt;
+ move_left_end_segments();
+ move_rght_end_segments();
+}
+
+void KBMTorus::move_left_end_segments() {
+ leftarm->setPoint(0,
+ 0, -torposy + sin(tortilt) * 2, -torposz - cos(tortilt) * 2,
+ 0.2, 0);
+ leftarm->setPoint(1,
+ 0, -torposy, -torposz,
+ 0.2, 0);
+ leftarm->setPoint(2,
+ 0, -torposy - sin(tortilt) * 2, -torposz + cos(tortilt) * 2,
+ 0.2, 0);
+
+ leftarm->setPoint(7,
+ 0, torposy + sin(tortilt) * 2, torposz - cos(tortilt) * 2,
+ 1.0, 0);
+ leftarm->setPoint(8,
+ 0, torposy, torposz,
+ 1.0, 0);
+ leftarm->setPoint(9,
+ 0, torposy - sin(tortilt) * 2, torposz + cos(tortilt) * 2,
+ 1.0, 0);
+ leftarm->compensateTwist();
}
void KBMTorus::create_leftarm() {
@@ -113,9 +145,9 @@ void KBMTorus::create_leftarm() {
profile.push_back(vec2( 1.0, 0.0));
profile.push_back(vec2( 0.0, -1.0));
- vec3 q0 = vec3(0, -torposy + sin(tortilt) * 2, -torposz - cos(tortilt) * 2);
- vec3 q1 = vec3(0, -torposy, -torposz);
- vec3 q2 = vec3(0, -torposy - sin(tortilt) * 2, -torposz + cos(tortilt) * 2);
+ vec3 q0 = vec3(0, 0, 0);
+ vec3 q1 = vec3(0, 0, 0);
+ vec3 q2 = vec3(0, 0, 0);
vec3 q3 = vec3(-0.3 * looprad,
-torposy - 3 * sin(tortilt),
@@ -126,24 +158,47 @@ void KBMTorus::create_leftarm() {
torposy + 3 * sin(tortilt),
torposz - 3 * cos(tortilt));
- vec3 q7 = vec3(0, torposy + sin(tortilt) * 2, torposz - cos(tortilt) * 2);
- vec3 q8 = vec3(0, torposy, torposz);
- vec3 q9 = vec3(0, torposy - sin(tortilt) * 2, torposz + cos(tortilt) * 2);
+ vec3 q7 = vec3(0, 0, 0);
+ vec3 q8 = vec3(0, 0, 0);
+ vec3 q9 = vec3(0, 0, 0);
vector<vec3> pts;
pts.push_back(q0); pts.push_back(q1); pts.push_back(q2);
pts.push_back(q3); pts.push_back(q4); pts.push_back(q5); pts.push_back(q6);
pts.push_back(q7); pts.push_back(q8); pts.push_back(q9);
vector<double> scales;
- scales.push_back(0.1); scales.push_back(0.1); scales.push_back(0.1);
- scales.push_back(0.1); scales.push_back(0.1);
- scales.push_back(0.1); scales.push_back(0.1);
- scales.push_back(0.5); scales.push_back(0.5); scales.push_back(0.5);
+ scales.push_back(0.0); scales.push_back(0.0); scales.push_back(0.0);
+ scales.push_back(0.2); scales.push_back(0.2);
+ scales.push_back(0.2); scales.push_back(0.2);
+ scales.push_back(0.0); scales.push_back(0.0); scales.push_back(0.0);
leftarm = new SplineCoaster(pts, profile, scales, 0.0, 0.0);
leftarm->setClosed(false);
- leftarm->compensateTwist();
+ move_left_end_segments();
+}
+
+void KBMTorus::move_rght_end_segments() {
+ rghtarm->setPoint(0,
+ 0, torposy - sin(tortilt) * 2, torposz + cos(tortilt) * 2,
+ 0.2, 0);
+ rghtarm->setPoint(1,
+ 0, torposy, torposz,
+ 0.2, 0);
+ rghtarm->setPoint(2,
+ 0, torposy + sin(tortilt) * 2, torposz - cos(tortilt) * 2,
+ 0.2, 0);
+
+ rghtarm->setPoint(7,
+ 0, -torposy - sin(tortilt) * 2, -torposz + cos(tortilt) * 2,
+ 1.0, 0);
+ rghtarm->setPoint(8,
+ 0, -torposy, -torposz,
+ 1.0, 0);
+ rghtarm->setPoint(9,
+ 0, -torposy + sin(tortilt) * 2, -torposz - cos(tortilt) * 2,
+ 1.0, 0);
+ rghtarm->compensateTwist();
}
void KBMTorus::create_rghtarm() {
@@ -153,9 +208,9 @@ void KBMTorus::create_rghtarm() {
profile.push_back(vec2( 1.0, 0.0));
profile.push_back(vec2( 0.0, -1.0));
- vec3 q0 = vec3(0, torposy - sin(tortilt) * 2, torposz + cos(tortilt) * 2);
- vec3 q1 = vec3(0, torposy, torposz);
- vec3 q2 = vec3(0, torposy + sin(tortilt) * 2, torposz - cos(tortilt) * 2);
+ vec3 q0 = vec3(0, 0, 0);
+ vec3 q1 = vec3(0, 0, 0);
+ vec3 q2 = vec3(0, 0, 0);
vec3 q3 = vec3(0.3 * looprad,
torposy + 3 * sin(tortilt),
@@ -166,22 +221,22 @@ void KBMTorus::create_rghtarm() {
-torposy - 3 * sin(tortilt),
-torposz + 3 * cos(tortilt));
- vec3 q7 = vec3(0, -torposy - sin(tortilt) * 2, -torposz + cos(tortilt) * 2);
- vec3 q8 = vec3(0, -torposy, -torposz);
- vec3 q9 = vec3(0, -torposy + sin(tortilt) * 2, -torposz - cos(tortilt) * 2);
+ vec3 q7 = vec3(0, 0, 0);
+ vec3 q8 = vec3(0, 0, 0);
+ vec3 q9 = vec3(0, 0, 0);
vector<vec3> pts;
pts.push_back(q0); pts.push_back(q1); pts.push_back(q2);
pts.push_back(q3); pts.push_back(q4); pts.push_back(q5); pts.push_back(q6);
pts.push_back(q7); pts.push_back(q8); pts.push_back(q9);
vector<double> scales;
- scales.push_back(0.1); scales.push_back(0.1); scales.push_back(0.1);
- scales.push_back(0.1); scales.push_back(0.1);
- scales.push_back(0.1); scales.push_back(0.1);
- scales.push_back(0.5); scales.push_back(0.5); scales.push_back(0.5);
+ scales.push_back(0.0); scales.push_back(0.0); scales.push_back(0.0);
+ scales.push_back(0.2); scales.push_back(0.2);
+ scales.push_back(0.2); scales.push_back(0.2);
+ scales.push_back(0.0); scales.push_back(0.0); scales.push_back(0.0);
rghtarm = new SplineCoaster(pts, profile, scales, 0.0, 0.0);
rghtarm->setClosed(false);
- rghtarm->compensateTwist();
+ move_rght_end_segments();
}
View
@@ -72,6 +72,9 @@ class KBMTorus {
void toggleUpVectors();
void dumpPoints();
+ double getTorTilt();
+ void changeTorTilt(double dtilt);
+
private:
/* High-level parameters */
float torposy;
@@ -88,6 +91,9 @@ class KBMTorus {
SplineCoaster *leftarm;
SplineCoaster *rghtarm;
+ void move_left_end_segments();
+ void move_rght_end_segments();
+
void create_leftarm();
void create_rghtarm();
};
View
@@ -487,8 +487,8 @@ void SplineCoaster::renderUpVectors() {
glColor3f(1.0f, 0.0f, 1.0f);
else
glColor3f(1.0f, 1.0f, 1.0f);
- drawVector(p2, n2);
- drawVector(p3, n3);
+ drawVector(p2, n2*2);
+ drawVector(p3, n3*2);
// Next, we have to project the two normals onto the segment bisecting
// plane for s2. To do this, we each normal, project it onto s2, and
@@ -508,9 +508,9 @@ void SplineCoaster::renderUpVectors() {
vec3 mid = (p2 + p3) / 2;
glColor3f(1.0f, 0.0f, 0.0f);
- drawVector(mid, proj2);
+ drawVector(mid, proj2*2);
glColor3f(0.0f, 1.0f, 0.0f);
- drawVector(mid, proj3);
+ drawVector(mid, proj3*2);
// Now that we have two vectors in the same plane, we can compare the
// unsigned angle between them based on their dot products. This is
@@ -572,7 +572,7 @@ void SplineCoaster::renderUpVectors() {
vec3 projnend = r * nend;
glColor3f(1.0f, 1.0f, 0.0f);
- drawVector(p2, projnend);
+ drawVector(p2, projnend*2);
globalTwist = myGlobalTwist;
}
@@ -609,6 +609,20 @@ void SplineCoaster::changePoint(int index,
clearDisplayList();
}
+void SplineCoaster::setPoint(int index,
+ double x, double y, double z, double css, double rot) {
+ SplinePoint* point = bsplinePts[index];
+
+ point->point[0] = x;
+ point->point[1] = y;
+ point->point[2] = z;
+
+ point->crossSectionScale = css;
+ point->azimuth = rot;
+
+ clearDisplayList();
+}
+
SplinePoint SplineCoaster::getPoint(int index) {
return *bsplinePts[index];
}
View
@@ -98,6 +98,7 @@ class SplineCoaster {
int getNumControlPoints();
void changePoint(int index, double dx, double dy, double dz, double dcss, double drot);
SplinePoint getPoint(int index);
+ void setPoint(int index, double x, double y, double z, double css, double rot);
// When closed, a strut is constructed from the last control point back to
// the first. When not closed, this strut is not constructed.
View
@@ -273,14 +273,15 @@ float LineEnergy::update_step_size(float old, float end) {
KBMEnergy::KBMEnergy(
KBMTorus *torus, double twist_weight) :
// each control point has x, y and z components, plus a cross-section
- // scale
- Energy(0.1f, 0.00001f, torus->getNumMovableControlPoints() * 4),
+ // scale. Additionally, there is a tilt for the end cap.
+ Energy(0.1f, 0.00001f, torus->getNumMovableControlPoints() * 4 + 1),
torus(torus),
twist_weight(twist_weight) {
log_energies();
}
void KBMEnergy::apply_change(VectorXf *chg) {
+ int numParams = chg->size();
int numPointsLeft = torus->getNumMovableControlPoints(KBMTorus::LEFTARM);
int numPointsRght = torus->getNumMovableControlPoints(KBMTorus::RGHTARM);
@@ -303,6 +304,9 @@ void KBMEnergy::apply_change(VectorXf *chg) {
torus->changePoint(KBMTorus::RGHTARM,
pi/4 + 3, dx, dy, dz, dcss, 0);
}
+
+ torus->changeTorTilt((*chg)[numParams - 1]);
+
torus->compensateTwist();
}
@@ -395,6 +399,7 @@ void KBMEnergy::log_energies() {
}
cout << " " << torus->getGlobalTwist(whicharm);
+ cout << " " << torus->getTorTilt();
cout << endl;
}
View
@@ -88,7 +88,7 @@ void display() {
if (viewMode == VIEW_THIRDPERSON) {
- glTranslatef(0,-2,-20 - zoom);
+ glTranslatef(0,-2,-35 - zoom);
applyMat4(viewport.orientation);
}

0 comments on commit 4236bcd

Please sign in to comment.