Skip to content

Commit

Permalink
Merge branch 'kbm' of github.com:avik-das/shape-optimization into kbm
Browse files Browse the repository at this point in the history
Conflicts:
	src/KBMTorus.cpp
	src/KBMTorus.h
	src/SplineCoaster.cpp
  • Loading branch information
avik-das committed Mar 7, 2012
2 parents db0d678 + ee84369 commit 4236bcd
Show file tree
Hide file tree
Showing 6 changed files with 111 additions and 30 deletions.
99 changes: 77 additions & 22 deletions src/KBMTorus.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand All @@ -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),
Expand All @@ -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() {
Expand All @@ -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),
Expand All @@ -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();
}
6 changes: 6 additions & 0 deletions src/KBMTorus.h
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,9 @@ class KBMTorus {
void toggleUpVectors();
void dumpPoints();

double getTorTilt();
void changeTorTilt(double dtilt);

private:
/* High-level parameters */
float torposy;
Expand All @@ -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();
};
Expand Down
24 changes: 19 additions & 5 deletions src/SplineCoaster.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down Expand Up @@ -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;
}
Expand Down Expand Up @@ -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];
}
Expand Down
1 change: 1 addition & 0 deletions src/SplineCoaster.h
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
9 changes: 7 additions & 2 deletions src/energy.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand All @@ -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();
}

Expand Down Expand Up @@ -395,6 +399,7 @@ void KBMEnergy::log_energies() {
}

cout << " " << torus->getGlobalTwist(whicharm);
cout << " " << torus->getTorTilt();
cout << endl;
}

Expand Down
2 changes: 1 addition & 1 deletion src/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ void display() {


if (viewMode == VIEW_THIRDPERSON) {
glTranslatef(0,-2,-20 - zoom);
glTranslatef(0,-2,-35 - zoom);
applyMat4(viewport.orientation);
}

Expand Down

0 comments on commit 4236bcd

Please sign in to comment.