Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
Build/

DSC.xcodeproj/xcuserdata/asny.xcuserdatad/xcschemes/xcschememanagement.plist

Expand All @@ -14,3 +15,5 @@ DSC.xcodeproj/project.xcworkspace/xcuserdata/asny.xcuserdatad/UserInterfaceState
DSC.xcodeproj/xcuserdata/asny.xcuserdatad/xcdebugger/Breakpoints.xcbkptlist

DSC.xcodeproj/xcuserdata/asny.xcuserdatad/xcdebugger/Breakpoints_v2.xcbkptlist

*userdata*
25 changes: 25 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
cmake_minimum_required(VERSION 3.6)
project(2D-DSC)

set(CMAKE_CXX_STANDARD 14)

if (APPLE)
# TODO for Mac
endif (APPLE)

if (UNIX)
# TODO for UNix
endif (UNIX)
if(WIN32)
# TODO for Windows
endif()


aux_source_directory(./src SRC)

include_directories(../GEL/src/GEL)

link_directories(../GEL)

add_library(2D-DSC SHARED ${SRC})
target_link_libraries(2D-DSC GEL)
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>IDEDidComputeMac32BitWarning</key>
<true/>
</dict>
</plist>
Binary file not shown.
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
<?xml version="1.0" encoding="UTF-8"?>
<Scheme
LastUpgradeVersion = "0900"
version = "1.3">
<BuildAction
parallelizeBuildables = "YES"
buildImplicitDependencies = "YES">
<BuildActionEntries>
<BuildActionEntry
buildForTesting = "YES"
buildForRunning = "YES"
buildForProfiling = "YES"
buildForArchiving = "YES"
buildForAnalyzing = "YES">
<BuildableReference
BuildableIdentifier = "primary"
BlueprintIdentifier = "7A51F3D417D6399200A8F8F2"
BuildableName = "libDSC.a"
BlueprintName = "DSC"
ReferencedContainer = "container:DSC.xcodeproj">
</BuildableReference>
</BuildActionEntry>
</BuildActionEntries>
</BuildAction>
<TestAction
buildConfiguration = "Debug"
selectedDebuggerIdentifier = "Xcode.DebuggerFoundation.Debugger.LLDB"
selectedLauncherIdentifier = "Xcode.DebuggerFoundation.Launcher.LLDB"
language = ""
shouldUseLaunchSchemeArgsEnv = "YES">
<Testables>
</Testables>
<AdditionalOptions>
</AdditionalOptions>
</TestAction>
<LaunchAction
buildConfiguration = "Release"
selectedDebuggerIdentifier = "Xcode.DebuggerFoundation.Debugger.LLDB"
selectedLauncherIdentifier = "Xcode.DebuggerFoundation.Launcher.LLDB"
language = ""
launchStyle = "0"
useCustomWorkingDirectory = "NO"
ignoresPersistentStateOnLaunch = "NO"
debugDocumentVersioning = "YES"
debugServiceExtension = "internal"
allowLocationSimulation = "YES">
<MacroExpansion>
<BuildableReference
BuildableIdentifier = "primary"
BlueprintIdentifier = "7A51F3D417D6399200A8F8F2"
BuildableName = "libDSC.a"
BlueprintName = "DSC"
ReferencedContainer = "container:DSC.xcodeproj">
</BuildableReference>
</MacroExpansion>
<AdditionalOptions>
</AdditionalOptions>
</LaunchAction>
<ProfileAction
buildConfiguration = "Release"
shouldUseLaunchSchemeArgsEnv = "YES"
savedToolIdentifier = ""
useCustomWorkingDirectory = "NO"
debugDocumentVersioning = "YES">
<MacroExpansion>
<BuildableReference
BuildableIdentifier = "primary"
BlueprintIdentifier = "7A51F3D417D6399200A8F8F2"
BuildableName = "libDSC.a"
BlueprintName = "DSC"
ReferencedContainer = "container:DSC.xcodeproj">
</BuildableReference>
</MacroExpansion>
</ProfileAction>
<AnalyzeAction
buildConfiguration = "Debug">
</AnalyzeAction>
<ArchiveAction
buildConfiguration = "Release"
revealArchiveInOrganizer = "YES">
</ArchiveAction>
</Scheme>
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>SchemeUserState</key>
<dict>
<key>DEMO.xcscheme</key>
<dict>
<key>orderHint</key>
<integer>3</integer>
</dict>
<key>DEMO.xcscheme_^#shared#^_</key>
<dict>
<key>orderHint</key>
<integer>3</integer>
</dict>
<key>DSC.xcscheme</key>
<dict>
<key>orderHint</key>
<integer>0</integer>
</dict>
</dict>
<key>SuppressBuildableAutocreation</key>
<dict>
<key>7A51F3D417D6399200A8F8F2</key>
<dict>
<key>primary</key>
<true/>
</dict>
</dict>
</dict>
</plist>
80 changes: 61 additions & 19 deletions src/DSC.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ namespace DSC2D

INTERFACE_COLOR = DARK_RED;
CROSSING_COLOR = RED;
OUTSIDE_COLOR = BLACK;
OUTSIDE_COLOR = GRAY;
DEFAULT_COLOR = DARK_BLUE;
OUTSIDE_FACE_COLOR = INVISIBLE;
DEFAULT_FACE_COLOR = BLUE;
Expand Down Expand Up @@ -126,7 +126,7 @@ namespace DSC2D
mesh->build(points.size()/3, &points[0], temp.size(), &temp[0], &faces[0]);
}

void DeformableSimplicialComplex::validity_check()
void DeformableSimplicialComplex::validity_check() const
{
for (auto fi = faces_begin(); fi != faces_end(); fi++) {
int i = 0;
Expand Down Expand Up @@ -186,19 +186,20 @@ namespace DSC2D

bool DeformableSimplicialComplex::move_vertex(node_key vid)
{

vec2 pos = get_pos(vid);
vec2 destination = get_destination(vid);
real l = Util::length(destination - pos);
if (l < 1e-4 * AVG_LENGTH)
if (l < 1e-6 * AVG_LENGTH)
{
return true;
}

real max_l = l*intersection_with_link(vid, destination) - 1e-4 * AVG_LENGTH;
real max_l = l*intersection_with_link(vid, destination) - 1e-6 * AVG_LENGTH;
l = Util::max(Util::min(0.5*max_l, l), 0.);
set_pos(vid, pos + l*Util::normalize(destination - pos));

if(Util::length(destination - get_pos(vid)) < 1e-4 * AVG_LENGTH)
if(Util::length(destination - get_pos(vid)) < 1e-6 * AVG_LENGTH)
{
return true;
}
Expand All @@ -209,12 +210,12 @@ namespace DSC2D
{
bool work = true;
int count = 0;
while(work && count < 10)
while(work && count < 50)
{
work = false;
for (auto vi = vertices_begin(); vi != vertices_end(); vi++)
{
if(is_movable(*vi))
if(is_movable(*vi)&&is_interface(*vi))
{
work = work | !move_vertex(*vi);
}
Expand All @@ -223,9 +224,11 @@ namespace DSC2D
fix_complex();
count++;
}

resize_complex();

// remove_needles();

HMesh::IDRemap cleanup_map;
cleanup_attributes(cleanup_map);

Expand Down Expand Up @@ -291,6 +294,19 @@ namespace DSC2D
return p;
}

std::vector<vec2> DeformableSimplicialComplex::get_design_variable_destinations()
{
std::vector<vec2> p;
for (auto vi = vertices_begin(); vi != vertices_end(); vi++)
{
if(is_movable(*vi))
{
p.push_back(get_destination(*vi));
}
}
return p;
}

std::vector<vec2> DeformableSimplicialComplex::get_interface_edge_positions()
{
std::vector<vec2> p;
Expand All @@ -305,6 +321,21 @@ namespace DSC2D
}
return p;
}

std::vector<vec2> DeformableSimplicialComplex::get_interface_edge_destinations()
{
std::vector<vec2> p;
for (auto eit = halfedges_begin(); eit != halfedges_end(); eit++)
{
if(is_interface(*eit))
{
auto hew = walker(*eit);
p.push_back(get_destination(hew.vertex()));
p.push_back(get_destination(hew.opp().vertex()));
}
}
return p;
}

vec2 DeformableSimplicialComplex::get_center()
{
Expand All @@ -326,6 +357,13 @@ namespace DSC2D
return positions;
}

std::vector<vec2> DeformableSimplicialComplex::get_pos(edge_key eid) const
{
auto hew = walker(eid);

return {get_pos(hew.vertex()), get_pos(hew.opp().vertex())};
}

vec2 DeformableSimplicialComplex::get_destination(node_key vid) const
{
return vec2(destination[vid]);
Expand Down Expand Up @@ -399,10 +437,10 @@ namespace DSC2D

void DeformableSimplicialComplex::set_destination(const node_key& vid, const vec2& dest)
{
if(is_movable(vid))
// if(is_movable(vid))
{
vec2 vec = dest - get_pos(vid);
clamp_vector(vid, vec);
// clamp_vector(vid, vec);
destination[vid] = get_pos(vid) + vec;
}
}
Expand Down Expand Up @@ -539,9 +577,10 @@ namespace DSC2D
}


bool DeformableSimplicialComplex::split(edge_key eid)
bool DeformableSimplicialComplex::split(edge_key eid, node_key * n)
{
if (!unsafe_editable(eid)) {
if (!unsafe_editable(eid))
{
return false;
}

Expand Down Expand Up @@ -569,6 +608,10 @@ namespace DSC2D
init_attributes(newf2, get_label(f2));

update_locally(vid);

if(n)
*n = vid;

return true;
}

Expand All @@ -589,7 +632,7 @@ namespace DSC2D
return true;
}

real DeformableSimplicialComplex::min_quality(const std::vector<edge_key>& eids, const vec2& pos_old, const vec2& pos_new)
real DeformableSimplicialComplex::min_quality(const std::vector<edge_key>& eids, const vec2& pos_old, const vec2& pos_new) const
{
real min_q = INFINITY;
for (auto e : eids)
Expand All @@ -605,7 +648,7 @@ namespace DSC2D
return min_q;
}

bool DeformableSimplicialComplex::is_collapsable(HMesh::Walker hew, bool safe)
bool DeformableSimplicialComplex::is_collapsable(HMesh::Walker hew, bool safe) const
{
if(safe)
{
Expand Down Expand Up @@ -770,13 +813,13 @@ namespace DSC2D
return Util::length(get_destination(hew.vertex()) - get_destination(hew.opp().vertex()));
}

real DeformableSimplicialComplex::min_edge_length(face_key fid)
real DeformableSimplicialComplex::min_edge_length(face_key fid) const
{
std::vector<vec2> p = get_pos(fid);
return Util::min(Util::min(Util::length(p[0] - p[1]), Util::length(p[1] - p[2])), Util::length(p[0] - p[2]));
}

real DeformableSimplicialComplex::min_angle(face_key fid)
real DeformableSimplicialComplex::min_angle(face_key fid) const
{
std::vector<vec2> p = get_pos(fid);
return Util::min_angle(p[0], p[1], p[2]);
Expand Down Expand Up @@ -1196,7 +1239,7 @@ namespace DSC2D
}
}


bool operator<(const DeformableSimplicialComplex::PQElem& e0, const DeformableSimplicialComplex::PQElem& e1)
{
return e0.pri > e1.pri;
Expand All @@ -1215,7 +1258,6 @@ namespace DSC2D
if((energy<0) && (t < 10000)){
Q.push(PQElem(energy, h, t));
}

}

void DeformableSimplicialComplex::add_one_ring_to_queue(HMesh::HalfEdgeAttributeVector<int>& touched, std::priority_queue<PQElem>& Q, node_key v, const HMesh::EnergyFun& efun)
Expand Down Expand Up @@ -1263,4 +1305,4 @@ namespace DSC2D
priority_queue_optimization(energy_fun);
}

}
}
Loading