-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
3 changed files
with
106 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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")); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters