Code Monkey home page Code Monkey logo

Comments (19)

LogWell avatar LogWell commented on July 17, 2024 1

In fact, there are four labels in total(maybe more). The current obj file only contains three of them (label 2 may represent skirt).

For a batch of data, I can map 0,1,2,3 to four colors, and then color it according to the label information.

from vedo.

marcomusy avatar marcomusy commented on July 17, 2024 1

Hi @LogWell
this looks related to a transparency problem in vtk.. though I must say I don't understand exactly why that happens.. This works for me:

from vtkplotter import *

settings.useDepthPeeling = True

m = load('00000.obj').texture('registered_tex_1_m.png')
m.show(axes=4)

from vedo.

marcomusy avatar marcomusy commented on July 17, 2024 1

various possibilities..:
if the points are projectable onto a plane (which seems to be the case) you can discard the existing triangles and recreate a new mesh with delaunay2D
or
try to recreate it with recoSurface()
besides
you can use clean(tol=0.01) to preprocess and reduce the points and/or use smoothMLS2D() to make the surface smoother.

finally - once you have the mesh - you can color the outside and inside differently with color() and backColor()

from vedo.

marcomusy avatar marcomusy commented on July 17, 2024

Hi
I'm adding now this functionality and let you know asap
M

from vedo.

sariths avatar sariths commented on July 17, 2024

@marcomusy Thanks. Please let me know if I can help out in any way. I just got started with VTK but I do have some experience in Python and data visualization.

from vedo.

marcomusy avatar marcomusy commented on July 17, 2024

please have a look at examples/mesh_coloring.py

mcol

from vedo.

sariths avatar sariths commented on July 17, 2024

This is pretty incredible!!

I just ran your example file with some of my manikins and it works great..
2018-07-09 15_16_12-window
..and just for fun, I tried a more complex model (with nearly 100,000 surfaces and missing geometry) and that loads too!
2018-07-09 15_13_13-window

I think this library could be used to visualize a whole lot of building science data in 3D.
cc: @mostaphaRoudsari

from vedo.

marcomusy avatar marcomusy commented on July 17, 2024

Thanks,
keep in mind you can control the scalarbar to have it horizontal e.i.:
vp.addScalarBar(man3, horizontal=True)

from vedo.

sariths avatar sariths commented on July 17, 2024

@marcomusy Thanks for the tip. Which API do you to refer to for Python-specifc functionality within VTK? I have come across an API and documentation for the C++ version, however, it appears that not all the classes and methods have been ported over to the Python version.

from vedo.

marcomusy avatar marcomusy commented on July 17, 2024

I typically use the latest version of vtk (8.1 as it comes in anaconda) so I guess all the c++ methods are ported to python, older vtk versions might not have the latest features. I don't think that there is anything like a specific python api for reference...
If you load any mesh at command line you should be able to get a message of which version you are running, e.g.:
./plotter.py anymesh.obj

from vedo.

sariths avatar sariths commented on July 17, 2024

I don't think that there is anything like a specific python api for reference...

That's the case with most libraries ported to Python, except PyQT. Anyway, thank you for getting this project started. I will circle back in case I come up with more "interesting" queries.

from vedo.

marcomusy avatar marcomusy commented on July 17, 2024

vtk documentation is not very good..
if you have any other questions/query don't hesitate to ask,
cheers
M

from vedo.

LogWell avatar LogWell commented on July 17, 2024

data

code:

from vtkplotter import *
import numpy as np

sc = load('scan_c.obj')
data_label = np.load('scan_labels.npy').reshape(-1)
sc.pointColors(data_label, alpha=1, mode='scalars')
show(sc, Text('seg', c='k'), bg='w', interactive=True)

question:

1,2: Shown in OpenFlipper and vtkplotter, difference caused by ?interpolation???
3,4: How to color a single element(vertex or face) without interpolation?
view

PS: In scan.obj, only v and vt are stored, but f indexes to vn. It can be opened in meshlab and OpenFlipper, exception handling should be done, can you handle such abnormal data?

PS: How to set transparent background?

from vedo.

marcomusy avatar marcomusy commented on July 17, 2024

Hi @LogWell please pull the latest commit and try the following:

from vtkplotter import load, show, colors
import numpy as np

sc = load('scan_c.obj')
data_label = np.load('scan_labels.npy').reshape(-1)

# Optionally build a lookup table of colors:
#                     scalar, color
lut = colors.makeLUT([( 0,   'pink'),
                      ( 1,   'green'),
                      ( 3,   'yellow'),
                      ], 
                      N=4, # specify total nr. of colors
                    )

sc.pointColors(data_label, cmap=lut).addScalarBar()

#sc.mapPointsToCells() # this would translate point data to cell data

# avoid interpolating cell colors:
sc.mapper.InterpolateScalarsBeforeMappingOff()
show(sc, bg='w')

image

PS: In scan.obj, only v and vt are stored, but f indexes to vn. It can be opened in meshlab and OpenFlipper, exception handling should be done, can you handle such abnormal data?

Unfortunately vtk seems unable to handle this faulty data..

PS: How to set transparent background?

from vtkplotter import settings
settings.screenshotTransparentBackground = True

from vedo.

LogWell avatar LogWell commented on July 17, 2024

NOTE: The red dot in the leftmost yellow circle in the previous image may be caused by abnormal data scan.obj , correct as shown in fig_1, same as in vtkplotter.

Q:

  1. How to color single point rather transm to face, like in fig_2? ref here?

  2. Thanks for your example of using colors.makeLUT. I'm a little confused about setting the correct color in fig_3.

fig

from vedo.

marcomusy avatar marcomusy commented on July 17, 2024
  1. consider the following where points can be overlapped to mesh if you wish:
from vtkplotter import load, show, makeLUT, Points
import numpy as np

sc = load('/home/musy/downloads/scan/scan_c.obj')
data_label = np.load('/home/musy/downloads/scan/scan_labels.npy').reshape(-1)

# build a lookup table of colors:
#              scalar, color
lut = makeLUT([( 0,   'red'),
               ( 1,   'green'),
               ( 3,   'gold'),
               ], 
               N=4, # specify total nr. of colors
              )

sc.pointColors(data_label, cmap=lut).addScalarBar()

# avoid interpolating cell colors:
sc.mapper.InterpolateScalarsBeforeMappingOff()

pts = Points(sc.coordinates()).pointColors(data_label, cmap=lut)

show(sc, pts, N=2, bg='w')

image

  1. make sure you have pulled the latest version from git.
    note that in your scalar file you only have values 0,1,3 and 2 is absent.
    Plus you have a typo "bule" instead of "blue".

Let me know if you can reproduce the above figure.

from vedo.

marcomusy avatar marcomusy commented on July 17, 2024

@LogWell

I realized that my first try at fixing this was not great.. :) I modified the makeLUT() function, so the above now becomes:

from vtkplotter import load, show, makeLUT, Points
import numpy as np

sc = load('/home/musy/downloads/scan/scan_c.obj')
data_label = np.load('/home/musy/downloads/scan/scan_labels.npy').reshape(-1)

# build a lookup table of colors:
#              scalar, color  alpha
lut = makeLUT([( 0,   'red'       ),
               ( 1,   'green', 0.5),
               ( 3,   'gold'      ),
               ],
              interpolate=False,
              )

sc.pointColors(data_label, cmap=lut).addScalarBar()

# avoid interpolating cell colors:
sc.mapper.InterpolateScalarsBeforeMappingOff()

pts = Points(sc.coordinates()).pointColors(data_label, cmap=lut)

show(sc, pts, N=2, bg='w')

this also includes setting opacities if a 3rd element is given in the list.
Hope this works for you.

from vedo.

LogWell avatar LogWell commented on July 17, 2024

Hi, marcomusy~

data

The result seems strange after I subdivided the mesh. It looks a little bit like a flip from the inside view, but the normal of faces are correct in meshlab.

How to solve this problem?

from vedo.

LogWell avatar LogWell commented on July 17, 2024

@marcomusy How to render a mesh like this(you can distinguish between inside and outside):

20200816_15:26:45
20200816_15:28:34
image

from vedo.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.