Commit f11a392e authored by Simon Boyé's avatar Simon Boyé

Vitelotte: fixed a bunch of bugs.

parent 6818d4d0
......@@ -62,6 +62,7 @@ protected:
typedef Eigen::SimplicialLDLT<StiffnessMatrix> SPDFactorization;
typedef Eigen::SparseLU<StiffnessMatrix> SymFactorization;
// typedef Eigen::SparseQR<StiffnessMatrix, Eigen::COLAMDOrdering<int> > SymFactorization;
typedef std::vector<SPDFactorization*> SPDBlocks;
typedef std::vector<SymFactorization*> SymBlocks;
......
......@@ -213,8 +213,8 @@ void FemSolver<_Mesh, _ElementBuilder>::factorize()
int size = m_ranges[k+1]-start;
// Skip unused, isolated nodes
// if(size == 1 && mat.coeffRef(start, start) == 0)
// continue;
if(size == 1 && mat.coeffRef(start, start) == 0)
continue;
StiffnessMatrix L(size,size);
L.reserve(size*20);
......@@ -232,7 +232,9 @@ void FemSolver<_Mesh, _ElementBuilder>::factorize()
L.finalize();
// std::cout << "range: " << start << " (" << m_perm[start] << "), " << size << "\n";
// std::cout << "range: " << start << " (" << m_perm[start] << "), "
// << size << ", nz=" << L.nonZeros() << " ("
// << 100. * L.nonZeros() / double(L.cols() * L.rows()) << "%)\n";
switch(m_type)
{
......@@ -299,12 +301,18 @@ FemSolver<_Mesh, _ElementBuilder>::solve()
switch(m_type)
{
case ElementBuilder::MATRIX_SPD:
m_x.middleRows(start,size) = m_spdBlocks[k]->solve(m_x.middleRows(start, size));
if(internal::checkEigenSolverError(*m_spdBlocks[k], m_error)) return;
if(m_spdBlocks[k])
{
m_x.middleRows(start,size) = m_spdBlocks[k]->solve(m_x.middleRows(start, size));
if(internal::checkEigenSolverError(*m_spdBlocks[k], m_error)) return;
}
break;
case ElementBuilder::MATRIX_SYMETRIC:
m_x.middleRows(start,size) = m_symBlocks[k]->solve(m_x.middleRows(start, size));
if(internal::checkEigenSolverError(*m_symBlocks[k], m_error)) return;
if(m_symBlocks[k])
{
m_x.middleRows(start,size) = m_symBlocks[k]->solve(m_x.middleRows(start, size));
if(internal::checkEigenSolverError(*m_symBlocks[k], m_error)) return;
}
break;
}
}
......
......@@ -153,7 +153,7 @@ FVElementBuilder<_Mesh, _Scalar>::
if(isPgc)
{
// std::cout << "Flat elem:\n";
// std::cout << "Flat elem: " << elem.point(0).transpose() << "\n";
// std::cout << " p0: " << elem.point(0).transpose() << "\n";
// std::cout << " p1: " << elem.point(1).transpose() << "\n";
// std::cout << " p2: " << elem.point(2).transpose() << "\n";
......@@ -186,6 +186,7 @@ FVElementBuilder<_Mesh, _Scalar>::
int ce1 = mesh.vertexGradientDummyNode(h1).idx();
int ce2 = mesh.vertexGradientDummyNode(h2).idx();
// std::cout << " ce1: " << ce1 << ", ce2: " << ce2 << "\n";
if(ce1 < 0 || ce2 < 0)
{
if(error) error->error("Invalid node");
......
......@@ -6,20 +6,33 @@
import sys
from sys import argv
from math import cos, sin, pi
from random import uniform
##################
def lerp(alpha, p0, p1):
return [ (1-alpha)*c0 + alpha*c1 for c0, c1 in zip(p0, p1) ]
def rand_vec(fact):
return ( uniform(-fact, fact), uniform(-fact, fact) )
def vec_sum(a, b):
return ( x+y for x, y in zip(a, b) )
##################
if len(argv) != 3:
print("Usage:", argv[0], "N_RINGS FILENAME")
if len(argv) == 3:
filename = argv[2]
nrings = int(argv[1])
noise = 0.
elif len(argv) == 4:
filename = argv[3]
nrings = int(argv[1])
noise = float(argv[2])
else:
print("Usage:", argv[0], "N_RINGS [NOISE] FILENAME")
exit(1)
filename = argv[2]
nrings = int(argv[1])
out = open(filename, 'w')
......@@ -27,14 +40,14 @@ sys.stdout = out
print("mvg 1.0")
print("attributes none")
print("v 0 0")
print("v", *rand_vec(noise))
for r in range(1, nrings+1):
for tri in range(6):
alpha = [ tri * pi/3, (tri+1) * pi/3 ]
p = [ [ cos(alpha[i]) * r, sin(alpha[i]) * r ] for i in range(2) ]
for v in range(r):
coords = lerp(v / r, p[0], p[1])
coords = vec_sum(lerp(v / r, p[0], p[1]), rand_vec(noise))
print("v", *coords)
inner = 0
......
......@@ -153,6 +153,14 @@ void VGMeshWithCurves::setNodesFromCurves()
if(hasEdgeValue()) edgeValueNode(*hit) = Node();
if(hasEdgeGradient()) edgeGradientNode(*hit) = Node();
}
for(VertexIterator vit = verticesBegin();
vit != verticesEnd(); ++vit)
{
if(isGradientConstraint(*vit))
{
removeGradientConstraint(*vit);
}
}
for(unsigned pci = 0; pci < nPointConstraints(); ++pci)
{
......@@ -182,10 +190,6 @@ void VGMeshWithCurves::setNodesFromCurves()
{
setGradientConstraint(vertex(pc), gradient(pc));
}
else
{
removeGradientConstraint(vertex(pc));
}
}
for(unsigned ci = 0; ci < nCurves(); ++ci)
......
......@@ -945,7 +945,7 @@ void SetPointConstraintGradient::redo()
void SetPointConstraintGradient::setGradient(const NodeGradient& gradient)
{
m_document->mesh().gradient(m_pc) = gradient;
m_document->markDirty(Document::DIRTY_NODE_VALUE | Document::DIRTY_CURVES_FLAG);
m_document->markDirty(Document::DIRTY_CONNECTIVITY | Document::DIRTY_CURVES_FLAG);
}
......
......@@ -226,7 +226,7 @@ void GLViewer::startup(const std::string& filename)
glEnable(GL_DEPTH_TEST);
glDepthFunc(GL_LEQUAL);
glEnable(GL_FRAMEBUFFER_SRGB);
// glEnable(GL_FRAMEBUFFER_SRGB);
glEnable(GL_BLEND);
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
......
......@@ -11,40 +11,11 @@
#include "solveCommand.h"
char* progName;
void usage(int returnValue = 127)
{
std::cout << "usage: " << progName << " [OPTIONS] COMMAND [CMD-OPTIONS]\n"
"Mvg toolkit: a set of tools to manipulate mvg files.\n"
"\n"
"Commands:\n"
" check IN Check IN mvg to ensure everything is right.\n"
" convert [-a ATTRS | --attrib ATTRS] IN OUT\n"
" Convert a mesh IN from a supported format to an mvg file OUT,\n"
" with attributes ATTRS. If ATTRS is not provided, keep the\n"
" default attributes if IN is a mvg file or default to fv.\n"
" finalize IN OUT\n"
" Finalize the mvg by setting nodes on all faces.\n"
"\n"
"Options:\n"
" -h, --help Display this message.\n"
" -v Verbose. Print extra informations.\n"
"\n";
exit(returnValue);
}
// Main -----------------------------------------------------------------------
int main(int argc, char** argv)
{
progName = argv[0];
Mvgtk mvgtk;
mvgtk.registerCommand<OutputCommand>("out");
......@@ -61,8 +32,7 @@ int main(int argc, char** argv)
mvgtk.registerCommand<SimplifyCommand>("simplify");
mvgtk.registerCommand<SolveCommand>("solve");
if(!mvgtk.parseArgs(argc, argv)) usage();
mvgtk.parseArgs(argc, argv);
return mvgtk.executeCommands()? EXIT_SUCCESS: EXIT_FAILURE;
// ArgMap commands;
......
#include <fstream>
#include <iostream>
#include <Patate/common/surface_mesh/objReader.h>
#include <Patate/vitelotte_io.h>
......@@ -22,6 +23,9 @@ int parseAttribSet(const std::string& attr)
}
// ////////////////////////////////////////////////////////////////////////////
MvgtkCommand::~MvgtkCommand()
{
}
......@@ -33,17 +37,6 @@ bool MvgtkCommand::parseArgs(int /*argc*/, char** /*argv*/, int& /*argi*/)
}
Mvgtk::Mvgtk()
{
opts.verbose = false;
m_argMap.insert(std::make_pair("-h", GlobalHelp));
m_argMap.insert(std::make_pair("--help", GlobalHelp));
m_argMap.insert(std::make_pair("-v", GlobalVerbose));
m_argMap.insert(std::make_pair("--verbose", GlobalVerbose));
}
bool OutputCommand::parseArgs(int argc, char** argv, int& argi)
{
if(argi < argc) {
......@@ -62,6 +55,20 @@ bool OutputCommand::execute(Mesh& mesh, const GlobalOptions* opts)
}
// ////////////////////////////////////////////////////////////////////////////
Mvgtk::Mvgtk()
{
opts.verbose = false;
m_argMap.insert(std::make_pair("-h", GlobalHelp));
m_argMap.insert(std::make_pair("--help", GlobalHelp));
m_argMap.insert(std::make_pair("-v", GlobalVerbose));
m_argMap.insert(std::make_pair("--verbose", GlobalVerbose));
}
Mvgtk::~Mvgtk()
{
for(FactoryMap::iterator it = m_factories.begin();
......@@ -73,14 +80,25 @@ Mvgtk::~Mvgtk()
}
void Mvgtk::printUsage(std::ostream& out, int exitCode) const {
out << "Usage: " << m_progName << " [OPTIONS] COMMAND [CMD-OPTION] [COMMAND [CMD-OPTION] [...]]\n";
out << "Mvg toolkit: a set of tools to manipulate mvg files.\n";
out << "\n";
out << "Commands:\n";
std::exit(exitCode);
}
bool Mvgtk::parseArgs(int argc, char** argv)
{
m_progName = argv[0];
int argi = 1;
std::string arg;
for(; argi < argc; ++argi)
{
arg = argv[argi];
if(arg.empty()) return false;
if(arg.empty()) printUsage(std::cerr);
else if(arg[0] == '-')
{
ArgMap::iterator opt = m_argMap.find(arg);
......@@ -89,7 +107,7 @@ bool Mvgtk::parseArgs(int argc, char** argv)
switch((*opt).second)
{
case GlobalHelp:
return false;
printUsage(std::cout, 0);
break;
case GlobalVerbose:
opts.verbose = true;
......@@ -114,11 +132,11 @@ bool Mvgtk::parseArgs(int argc, char** argv)
{
arg = argv[argi++];
FactoryMap::iterator it = m_factories.find(arg);
if(it == m_factories.end()) return false;
if(it == m_factories.end()) printUsage(std::cerr);
MvgtkCommand* cmd = it->second->create();
m_commands.push_back(cmd);
if(!cmd->parseArgs(argc, argv, argi)) return false;
if(!cmd->parseArgs(argc, argv, argi)) printUsage(std::cerr);
}
return true;
......
......@@ -5,6 +5,7 @@
#include <list>
#include <map>
#include <string>
#include <ostream>
#include <Patate/vitelotte.h>
......@@ -66,6 +67,8 @@ public:
m_factories.insert(std::make_pair(name, new GenericFactory<T>()));
}
void printUsage(std::ostream& out, int exitCode = 127) const;
bool parseArgs(int argc, char** argv);
bool executeCommands();
......@@ -92,6 +95,7 @@ private:
ArgMap m_argMap;
FactoryMap m_factories;
CommandList m_commands;
std::string m_progName;
std::string m_inFilename;
};
......
......@@ -6,8 +6,8 @@ bool solveGeneric(Mesh& mesh)
{
Solver solver(&mesh);
solver.build();
solver.factorize();
solver.sort();
solver.factorize();
if(solver.error().status() == Vitelotte::SolverError::STATUS_WARNING)
{
......
......@@ -25,8 +25,8 @@ void solveGeneric(Mesh& mesh)
{
Solver solver(&mesh);
solver.build();
solver.factorize();
solver.sort();
solver.factorize();
if(solver.error().status() == Vitelotte::SolverError::STATUS_WARNING)
{
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment