Skip to content

Commit

Permalink
Added extrusion surface
Browse files Browse the repository at this point in the history
  • Loading branch information
SonSang committed Nov 2, 2020
1 parent 8d6fcc9 commit 47d28f4
Show file tree
Hide file tree
Showing 3 changed files with 106 additions and 1 deletion.
62 changes: 62 additions & 0 deletions Surface/ExtrusionSurface3d.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
#include "ExtrusionSurface3d.h"

namespace MN {
ExtrusionSurface3d ExtrusionSurface3d::create(const std::vector<Freeform2dc::Ptr>& profile) {
ExtrusionSurface3d surface;
surface.profile = profile;
return surface;
}
ExtrusionSurface3d::Ptr ExtrusionSurface3d::createPtr(const std::vector<Freeform2dc::Ptr>& profile) {
return std::make_shared<ExtrusionSurface3d>(create(profile));
}

const std::vector<Freeform2dc::Ptr>& ExtrusionSurface3d::getProfile() const {
return profile;
}
void ExtrusionSurface3d::setProfile(const std::vector<Freeform2dc::Ptr>& profile) {
this->profile = profile;
}

// u : Parameter for profile curve evaluation
// v : Parameter for extrusion along Z axis
Vec3 ExtrusionSurface3d::evaluate(int curveID, Real u, Real v) const {
Vec2 pt = profile[curveID]->evaluate(u);
return { pt[0], pt[1], v };
}
Vec3 ExtrusionSurface3d::differentiate(int curveID, Real u, Real v, int uOrder, int vOrder) const {
if (uOrder == 0 && vOrder == 0)
return evaluate(curveID, u, v);
else if (uOrder == 1 && vOrder == 0) {
auto curveDeriv = profile[curveID]->differentiate(u, 1);
return { curveDeriv[0], curveDeriv[1], 0 };
}
else if (uOrder == 0 && vOrder == 1) {
return { 0, 0, 1 };
}
else if (uOrder == 2 && vOrder == 0) {
auto curveDeriv = profile[curveID]->differentiate(u, 2);
return { curveDeriv[0], curveDeriv[1], 0 };
}
else if (uOrder == 1 && vOrder == 1) {
return { 0, 0, 0 };
}
else if (uOrder == 0 && vOrder == 2) {
return { 0, 0, 0 };
}
else if (uOrder == 3 && vOrder == 0) {
auto curveDeriv = profile[curveID]->differentiate(u, 3);
return { curveDeriv[0], curveDeriv[1], 0 };
}
else if (uOrder == 2 && vOrder == 1) {
return { 0, 0, 0 };
}
else if (uOrder == 1 && vOrder == 2) {
return { 0, 0, 0 };
}
else if (uOrder == 0 && vOrder == 3) {
return { 0, 0, 0 };
}
else
throw(std::runtime_error("Extrusion surface differentiation is only allowed up to 2nd derivatives"));
}
}
43 changes: 43 additions & 0 deletions Surface/ExtrusionSurface3d.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
/*
*******************************************************************************************
* Author : Sang Hyun Son
* Email : [email protected]
* Github : github.com/SonSang
*******************************************************************************************
*/

#ifndef __MN_EXTRUSION_SURFACE_3D_H__
#define __MN_EXTRUSION_SURFACE_3D_H__

#ifdef _MSC_VER
#pragma once
#endif

#include "../Freeform.h"
#include "../Curve/BsplineCurve2d.h"
#include <memory>

namespace MN {
class ExtrusionSurface3d : public Freeform3ds {
private:
ExtrusionSurface3d() = default;

// Profile curve on XY plane that is extruded along Z axis
std::vector<Freeform2dc::Ptr> profile;
public:
using Ptr = std::shared_ptr<ExtrusionSurface3d>;

static ExtrusionSurface3d create(const std::vector<Freeform2dc::Ptr>& profile);
static Ptr createPtr(const std::vector<Freeform2dc::Ptr>& profile);

const std::vector<Freeform2dc::Ptr>& getProfile() const;
void setProfile(const std::vector<Freeform2dc::Ptr>& profile);

// u : Parameter for profile curve evaluation
// v : Parameter for extrusion along Z axis
virtual Vec3 evaluate(int curveID, Real u, Real v) const;
virtual Vec3 differentiate(int curveID, Real u, Real v, int uOrder, int vOrder) const;
};
}

#endif
2 changes: 1 addition & 1 deletion Surface/RevolutionSurface3d.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,6 @@ namespace MN {
return { curvePoint[0] * sin(v), 0, curvePoint[0] * -cos(v) };
}
else
throw(std::runtime_error("Bezier surface differentiation is only allowed up to 2nd derivatives"));
throw(std::runtime_error("Revolution surface differentiation is only allowed up to 2nd derivatives"));
}
}

0 comments on commit 47d28f4

Please sign in to comment.