i've made further changes to the texture atlas plugin - it should now work
with negative uv coords. it is crashing, however on line 197:
it causes a segmentation fault, that i've backtraced to qpainter. This does
not crash when I do not try to scale the qimage before converting it to a
qpixmap. any suggestions? I've tried calling the qpainter destructor
before resizing, but that doesn't help.
http://meshlab.svn.sourceforge.net/viewvc/meshlab/trunk/meshlab/src/meshlabplugins/filter_texture/filter_texture.cpp?revision=2258&view=markup
imran
On Wed, May 21, 2008 at 8:00 AM, skunkwerk <sku...@gm...> wrote:
> thanks Paolo,
> i want to get the first approach working before I try the second one.
>
> 1) is the current way I'm computing the maximum span correct?
> 2) could you please explain what you mean by 'relocating each triangle as
> close as possible to the origin'? by origin, you mean the top-left corner
> of the texture? are you talking about moving the vertices of the triangle,
> or the UV coordinates?
>
> imran
>
>
> On Tue, May 20, 2008 at 10:17 PM, Paolo Cignoni <pao...@is...>
> wrote:
>
>> Yes, it is not the worst case, but it is something that can happen.
>>
>> I think that you just need to compute the max span, relocate each triangle
>> as close as possible to the origin and then repeat the texture as needed,
>>
>> Obviously the approach 2): clipping the mesh along the integer values of
>> the tex coords is always a good safe option.
>> in your case it would have transformed the two triangle mesh in a grid of
>> 5x5 vertices and 32 triangles arranges in a regular grid.
>>
>> You have to define the edge predicate that says what edges have to be
>> splitten (the one with texcoords spanning more than 1
>> and the rule to find the position and interpolated values of the new
>> vertices. Look at the refine.h file and to the midpoint and EdgeLen classes.
>>
>> P.
>>
>>
>>
>> skunkwerk wrote:
>>
>> thanks Paolo,
>> I think I know what you mean, but is that the worst-case? In the
>> drawing I made here:
>> www.akbars.net/texcoords.png
>> assume each square is composed of two triangles (denoted by the red
>> line). The first square shows the normal 0-1 texcoords, no problem. the
>> second square shows what I think it would look like when the texture is
>> repeated twice along both axes, and likewise for the last square. The
>> reason I was thinking about finding the maximum UV coordinates was that I
>> could then generate that many copies (so the texture looks like the last
>> square) and then for faces that have UVs < 4 (in this case), i'd divide by
>> the maximum UVs. So for the second square 2,0 would correspond to 2/4=1/2,
>> 0.
>>
>> by the span of each triangle, i assume you mean the difference between the
>> maximum & mininum of the vertexes UV coordinates? with my example, both our
>> approaches would be the same I think as the last square's triangle starts at
>> 0 and goes to 4 at the bottom. but that obviously wouldn't always be the
>> case. so to finalize, what you are suggesting is:
>>
>> 1) generate an array of Point2f that will store the maximum difference in
>> the u & v coordinates for each texture index
>> 2) iterate through all faces, and for each face do 6 subtractions to
>> figure out the maximum difference for the U & V coordinates of vertexes in
>> that face
>> 3) if the value computed in 2) is greater than the value stored in the
>> array from 1), assign that value to the array
>> 4) when done, copy the texture the necessary number of times (as
>> indicated in the array), with values rounded up to the nearest integer
>> 5) iterate through faces and adjust UV coordinates by the new dimensions
>> of each texture
>>
>> imran
>>
>> On Tue, May 20, 2008 at 4:08 PM, Paolo Cignoni <pao...@is...>
>> wrote:
>>
>> I think that with a bit of care you can safely apply a same modulo
>> operation to the tex coords of the vertex of a same face so that you can
>> relocate it as close as possible to the origin of the uv coord system
>>
>> Explaining better. consider a model of a wall, tessllated (100x100
>> vertexes arranged in a regular grid), this wall is textured with a brick
>> texture that is tiled 30 times along u and 40 times along v. There is no
>> need to repeat 30x40 times the original texture simply because each triangle
>> will not span over many copies of the original texture but in the worst case
>> at most two. So in this particular case the needed texture size will be only
>> 2x2 times
>> In other words you have to look at the maximum span of each triangle, not
>> the absolute maximum/minimum.
>>
>> I have not seen good documents on the web explaining all the gory details
>> of this process. Keep this sturff them documented in the wiki :)
>>
>> Cheers
>> p.
>>
>>
>> skunkwerk wrote:
>>
>> thanks Paolo,
>> i'm working on supporting tiling textures right now for the atlas.
>>
>> i was looking at some 3d models - i have UVs in some of them that are
>> 67,-43. That would mean I would have to repeat that texture 67 times in the
>> x direction, and 43 times in the y, correct? Do I have to find the maximum
>> U & V coordinate of each textures' faces, and scale by that factor? what if
>> a different face is using the same texture, but not tiled? are there any
>> resources on the web for how to do this correctly?
>>
>> regards,
>> imran
>>
>> On Mon, May 19, 2008 at 2:04 PM, Paolo Cignoni <pao...@is...>
>> wrote:
>>
>> I would like to avoid the use of shaders, it seems to me a too not general
>> solution. Far from the mesh processing spirit of MeshLab.
>>
>> There are two solutions
>> 1) repeating. surely works, but increase the size of the final texture.
>> 2) clipping the triangles. a bit harder. as a negative side it changes the
>> topology of the mesh, increasing its complexity in terms of number of
>> triangles and vertices. Luckyly enough the vcg library offers methods for
>> this kind of clipping that make it in a almost automatic way. Look at the
>> refine classes.
>>
>> Imho both of the two solution are viable. The best things could be to
>> offer both options to the user and let him choose :)
>>
>> I would not consider resampling here. it is somethng that you can always
>> perform (and probably in a better way) outside meshlab with any image tool,
>> without touching at all the mesh.
>>
>> Do not concentrate too much on the size of the compressed textures. I do
>> not think that it is the most important issue here.
>>
>> Cheers and thanks for your help
>> p.
>>
>>
>>
>> skunkwerk wrote:
>>
>> thanks Paolo,
>> page 10 of the paper here:
>> ftp://download.nvidia.com/developer/NVTextureSuite/Atlas_Tools/Texture_Atlas_Whitepaper.pdf
>> discusses this issue, and says you can either use pixel shaders (which
>> might be possible in meshlab, but not generic viewers) or just repeat the
>> texture however many times necessary in the atlas itself (wrap or mirror
>> modes) - i did a quick test in photoshop with a single and tiled texture to
>> see if it would be able to detect the tiling and not increase the file size
>> - however the original file was 240k, and the tiled file ended up being 342k
>> when using PNG. the other option might be to simply resize the tiled
>> textures to fit into the size occupied by the original texture - but you
>> would decrease the resolution by doing so. but the 3d viewer at the default
>> zoom would already display a lower-resolution version of the texture if it
>> must be repeated within a fixed area, right? so the issue would only be
>> visible at higher zoom levels - when you might expect the resolution of a
>> tiled texture to increase, but doesn't. perhaps we could have a
>> user-selectable value that determines how we tradeoff texture atlas size and
>> tiled texture resolution?
>>
>> graci,
>> imran
>>
>> On Sun, May 18, 2008 at 10:58 PM, Paolo Cignoni <
>> pao...@is...> wrote:
>>
>> skunkwerk wrote:
>> > thanks Paolo,
>> > sorry - i should have caught that. I'm testing out the code right
>> > now, and I need confirmation of UV coordinate formats:
>> >
>> > 1) if the coordinates are >1 that means the textures are to be
>> > repeated/tiled, correct? but meshlab can handle this, I don't need to
>> > change anything.
>> > 2) what do negative uv coordinates mean? I assumed the origin (0,0)
>> > was at the top-left corner of the textures. I don't see how you could
>> > have negative uv coordinates (as i'm seeing in some models) unless the
>> > origin is in the center.
>> >
>> > cheers,
>> > imran
>> >
>> yes texture coords out of the [0..1] range mean that the mesh is using
>> tiling and assuming that the texture is tiled. Tiling works also in the
>> negative space.
>>
>> Note that when a mesh is using tiling the atalsing procedure it is not
>> very simple.
>> a simple clamping the the coords does not work verywell and can produce
>> weird results.
>>
>> For example a triangle spanning from 0.9 to 1.1. cannot be replaced with
>> a triangle spanning from 0.9 to 0.1, instead of simply crossing the
>> border thenewe traiangle crosses the whole texture. In this case the
>> only correct solution, i fear, is to split the triangle in two along the
>> 1.0 tex coord value, so that we have two trianbgles, a first one
>> spanning from 0.9 to 1.0 and a second one spanning from 0.0 to 0.1.
>>
>> - as a first option do a modulo and simply issue a warning.
>> - as a second option we should clip the mesh. It can be done by using
>> the refineE and using a edge predicate that splits the edge only if its
>> textture coords are not inside the 0.1 range. Multiple passes could be
>> required (separately for each texture coord axis)
>>
>> cheers
>> p.
>>
>>
>>
>> --
>> Paolo Cignoni -- Senior Researcher
>> Visual Computing Laboratory - ISTI - CNR
>> http://vcg.isti.cnr.it/~cignoni <http://vcg.isti.cnr.it/%7Ecignoni>
>>
>> ISTI - CNR
>> Via Moruzzi 1,
>> 56124 Pisa
>> ITALY
>>
>>
>>
>> -------------------------------------------------------------------------
>> This SF.net email is sponsored by: Microsoft
>> Defy all challenges. Microsoft(R) Visual Studio 2008.
>> http://clk.atdmt.com/MRT/go/vse0120000070mrt/direct/01/
>> _______________________________________________
>> Meshlab-devel mailing list
>> Mes...@li...
>> https://lists.sourceforge.net/lists/listinfo/meshlab-devel
>>
>>
>>
>> -------------------------------------------------------------------------
>> This SF.net email is sponsored by: Microsoft
>> Defy all challenges. Microsoft(R) Visual Studio 2008.
>> http://clk.atdmt.com/MRT/go/vse0120000070mrt/direct/01/
>>
>>
>> _______________________________________________
>> Meshlab-devel mailing list
>> Mes...@li...
>> https://lists.sourceforge.net/lists/listinfo/meshlab-devel
>>
>>
>>
>> --
>> Paolo Cignoni -- Senior Researcher
>> Visual Computing Laboratory - ISTI - CNR
>> http://vcg.isti.cnr.it/~cignoni <http://vcg.isti.cnr.it/%7Ecignoni>
>>
>> ISTI - CNR
>> Via Moruzzi 1,
>> 56124 Pisa
>> ITALY
>>
>>
>> -------------------------------------------------------------------------
>> This SF.net email is sponsored by: Microsoft
>> Defy all challenges. Microsoft(R) Visual Studio 2008.
>> http://clk.atdmt.com/MRT/go/vse0120000070mrt/direct/01/
>> _______________________________________________
>> Meshlab-devel mailing list
>> Mes...@li...
>> https://lists.sourceforge.net/lists/listinfo/meshlab-devel
>>
>>
>>
>> -------------------------------------------------------------------------
>> This SF.net email is sponsored by: Microsoft
>> Defy all challenges. Microsoft(R) Visual Studio 2008.
>> http://clk.atdmt.com/MRT/go/vse0120000070mrt/direct/01/
>>
>>
>> _______________________________________________
>> Meshlab-devel mailing list
>> Mes...@li...
>> https://lists.sourceforge.net/lists/listinfo/meshlab-devel
>>
>>
>>
>> --
>> Paolo Cignoni -- Senior Researcher
>> Visual Computing Laboratory - ISTI - CNR
>> http://vcg.isti.cnr.it/~cignoni <http://vcg.isti.cnr.it/%7Ecignoni>
>>
>> ISTI - CNR
>> Via Moruzzi 1,
>> 56124 Pisa
>> ITALY
>>
>>
>> -------------------------------------------------------------------------
>> This SF.net email is sponsored by: Microsoft
>> Defy all challenges. Microsoft(R) Visual Studio 2008.
>> http://clk.atdmt.com/MRT/go/vse0120000070mrt/direct/01/
>> _______________________________________________
>> Meshlab-devel mailing list
>> Mes...@li...
>> https://lists.sourceforge.net/lists/listinfo/meshlab-devel
>>
>>
>> ------------------------------
>>
>> -------------------------------------------------------------------------
>> This SF.net email is sponsored by: Microsoft
>> Defy all challenges. Microsoft(R) Visual Studio 2008.
>> http://clk.atdmt.com/MRT/go/vse0120000070mrt/direct/01/
>>
>> ------------------------------
>>
>> _______________________________________________
>> Meshlab-devel mailing list
>> Mes...@li...
>> https://lists.sourceforge.net/lists/listinfo/meshlab-devel
>>
>>
>>
>> --
>> Paolo Cignoni -- Senior Researcher
>> Visual Computing Laboratory - ISTI - CNR
>> http://vcg.isti.cnr.it/~cignoni <http://vcg.isti.cnr.it/%7Ecignoni>
>>
>> ISTI - CNR
>> Via Moruzzi 1,
>> 56124 Pisa
>> ITALY
>>
>>
>> -------------------------------------------------------------------------
>> This SF.net email is sponsored by: Microsoft
>> Defy all challenges. Microsoft(R) Visual Studio 2008.
>> http://clk.atdmt.com/MRT/go/vse0120000070mrt/direct/01/
>> _______________________________________________
>> Meshlab-devel mailing list
>> Mes...@li...
>> https://lists.sourceforge.net/lists/listinfo/meshlab-devel
>>
>>
>
|