gilbo / cork

3D Boolean / CSG Library
Other
406 stars 173 forks source link

remesh example? #20

Open danhambleton opened 9 years ago

danhambleton commented 9 years ago

Hi there,

I was wondering how to use the remesh functions (or in general, how to interact with mesh.h) - is there some example code I could take a look at? Ideally, I would like to input a .off file and have it remesh based min/max edge length.

Do I need to implement my own VertData and TriData stucts? It looks like there are some conditions that need these need to satisfy, but I'm not sure what exactly they are.

Any help is most appreciated!

gilbo commented 9 years ago

You need to provide some member functions in the vert and tri data structs, but I don't remember which off the top of my head. The compiler will yell at you until they're all there. You can also look at my toptop code, which uses the same underlying data structures.

-- Gilbert

On May 5, 2015, at 11:33 AM, danhambleton notifications@github.com wrote:

Hi there,

I was wondering how to use the remesh functions (or in general, how to interact with mesh.h) - is there some example code I could take a look at? Ideally, I would like to input a .off file and have it remesh based min/max edge length.

Do I need to implement my own VertData and TriData stucts? It looks like there are some conditions that need these need to satisfy, but I'm not sure what exactly they are.

Any help is most appreciated!

― Reply to this email directly or view it on GitHub.

danhambleton commented 9 years ago

Thanks! So, something like:

struct ModelerVertex : public MinimalVertexData, public RemeshVertexData
{

};

struct ModelerTriangle : public MinimalTriangleData, public RemeshTriangleData
{
    //void merge(const ModelerTriangle &, const ModelerTriangle &) {}
    //static void split(ModelerTriangle &, ModelerTriangle &,
    //                  const ModelerTriangle &) {}
    //void move(const ModelerTriangle &) {}
    //void subdivide(SubdivideTriInput<ModelerVertex,ModelerTriangle>) {}
};

When I add this to my (vs2012) project I get a bunch of LNK2005 errors,,,

image

Have you run in to this before? Might just be a windows thing...

danhambleton commented 9 years ago

To clarify, just defining these structs generates the error - the code compiled fine before.

gilbo commented 9 years ago

Since a lot of the code is template code, that’s unsurprising that adding the structs could cause an error. I’m not sure what’s going wrong from the errors you posted. It looks like it’s complaining about having the << operator not be defined.

However, I’d guess that this is more likely an issue with how you’re using the template system. Unfortunately C++ is quite finicky about how templates interact with object files. You might have defined something twice and then are getting name conflicts at link time. But again, it’s hard to say.

— Gilbert

On May 5, 2015, at 3:27 PM, danhambleton notifications@github.com wrote:

To clarify, just defining these structs generates the error - the code compiled fine before.

— Reply to this email directly or view it on GitHub.

danhambleton commented 9 years ago

I actually get this error simply by including mesh.h in the wincork main...

Full error here:

Error   7   error LNK2005: "class std::basic_ostream<char,struct std::char_traits<char> > & __cdecl operator<<(class std::basic_ostream<char,struct std::char_traits<char> > &,struct TopoEdge const &)" (??6@YAAAV?$basic_ostream@DU?$char_traits@D@std@@@std@@AAV01@ABUTopoEdge@@@Z) already defined in cork.obj  D:\ThirdParty\cork\win\wincork\main.obj

I don't have much experience with templates so I'm at a bit of a loss! I'll read through the toptop code a bit more carefully...

gilbo commented 9 years ago

Look at this part of the error: "already defined in cork.obj" The problem is that you're trying to link files with redundant (possibly conflicting!) definitions of the mesh.

On May 6, 2015, at 9:20 AM, danhambleton notifications@github.com wrote:

I actually get this error simply by including mesh.h in the wincork main...

Full error here:

Error 7 error LNK2005: "class std::basic_ostream<char,struct std::char_traits > & __cdecl operator<<(class std::basic_ostream<char,struct std::char_traits > &,struct TopoEdge const &)" (??6@YAAAV?$basic_ostream@DU?$char_traits@D@std@@@std@@AAV01@ABUTopoEdge@@@Z) already defined in cork.obj D:\ThirdParty\cork\win\wincork\main.obj I don't have much experience with templates so I'm at a bit of a loss! I'll read through the toptop code a bit more carefully...

― Reply to this email directly or view it on GitHub.

danhambleton commented 9 years ago

I understand the gist of the error and am totally fine with working away on my own on this (i.e. this is open source code and you probably don't want to be answering these questions!).

However, I'm literally just including your mesh.h in the wincork main and getting that linker error - is this expected behaviour?

Anyway, thanks for your time so far!

gilbo commented 9 years ago

Ok, here’s the quick simple answer from scanning the library (haven’t looked at the code in a while)

Notice the following include structure:

cork.cpp includes mesh.h includes cork.h

main.cpp includes cork.h

This is because I was trying to create a C-friendly interface for the library. Effectively cork.h/cork.cpp implement that wrapper and main.cpp just implements a simple command-line tool interface to the library.

The problem you’re having if you include mesh.h in main.cpp is that you’ve now included mesh.h (which is really an enormous chunk of the library thanks to templates having to be entirely in headers) in two different .cpp files. Each of those .cpp files is getting compiled into a .o file and then those are getting linked together. To reiterate, the problem is that you’re compiling two separate versions of the Mesh type.

FIX: you can fix this by working with mesh.h from cork.cpp, or if you have your own project, you can use cork.h/cork.cpp as an example for how you should implement your own wrapper around the CPP cork library interface. Make sure mesh.h is only included in this one .cpp file for the wrapper.

Ok, here’s the more precision fix after looking in a bit more detail.

The TopoTri, TopoEdge etc. operator<< functions are defined in a header (mesh.topocache.tpp) and so the problem is that you’re getting two copies of those symbols. You might be able to fix that by just changing those functions to have the ‘static inline’ keywords, which is a standard workaround to the problem of having functions defined in header files… (I could be wrong about that)

I can’t promise that the precision fix will fix everything.

— Gilbert

On May 6, 2015, at 2:38 PM, danhambleton notifications@github.com wrote:

I understand the gist of the error and am totally fine with working away on my own on this (i.e. this is open source code and you probably don't want to be answering these questions!).

However, I'm literally just including your mesh.h in the wincork main and getting that linker error - is this expected behaviour?

Anyway, thanks for time so far!

— Reply to this email directly or view it on GitHub.

danhambleton commented 9 years ago

Thanks! This is exactly what I needed.

danhambleton commented 9 years ago

Works great:

image

fangq commented 8 years ago

@danhambleton, do you mind sharing your lines for the remeshing work? just want to get some ideas how to apply the remesh feature after a boolean operation. thanks!

mortmaire commented 8 years ago

@danhambleton , your example is something I really need right now. Shame you didn't include it.

mortmaire commented 8 years ago

Funny thing - I actually spend last 2 weeks trying to recreate mesh library JUST TO GET THIS REMESH OPTION YOU DID NOT GIVE US, @danhambleton .

fangq commented 4 years ago

FYI, the remesh function is now exposed in my fork as -remesh in out, also double-dash commands, like --command, apply a remesh to the boolean output, see

https://github.com/fangq/cork/commit/33bea813f6936f55ec4b2b12ae55f4c878bbc105