Comments (14)
from vedo.
You can use cmap()
.
from vedo.
Hello @marcomusy
Kindly how I may expand this code for more than three segments
I mean in my case, I'm extracting connected components of the mesh like this:
s = Sphere(res=12)
#some code for extracting connected components
getting this: [[0, 152, 162, 172, 182, 192, 202, 212, 222, 232, 2, 12, 22, 32, 42, 52, 62, 72, 82, 92, 102, 112, 122, 132, 142],
[1, 41, 31, 21, 11, 241, 231, 221, 211, 201, 191, 181, 171, 161, 151, 141, 131, 121, 111, 101, 91, 81, 71, 61, 51],
[3, 13, 23, 33, 43, 53, 63, 73, 83, 93, 103, 113, 123, 133, 143, 153, 163, 173, 183, 193, 203, 213, 223, 233, 234, 4, 14, 24, 34, 44, 54, 64, 74, 84, 94, 104, 114, 124, 134, 144, 154, 164, 174, 184, 194, 204, 214, 224, 225, 235, 5, 15, 25, 35, 45, 55, 65, 75, 85, 95, 105, 115, 125, 135, 145, 155, 165, 175, 185, 195, 205, 215, 216, 226, 236, 6, 16, 26, 36, 46, 56, 66, 76, 86, 96, 106, 116, 126, 136, 146, 156, 166, 176, 186, 196, 206, 207, 197, 187, 177, 167, 157, 147, 137, 127, 117, 107, 97, 87, 77, 67, 57, 47, 37, 27, 17, 7, 237, 227, 217, 218, 208, 198, 188, 178, 168, 158, 148, 138, 128, 118, 108, 98, 88, 78, 68, 58, 48, 38, 28, 18, 8, 238, 228, 229, 219, 209, 199, 189, 179, 169, 159, 149, 139, 129, 119, 109, 99, 89, 79, 69, 59, 49, 39, 29, 19, 9, 239, 240, 10, 20, 30, 40, 50, 60, 70, 80, 90, 100, 110, 120, 130, 140, 150, 160, 170, 180, 190, 200, 210, 220, 230]]
These are the indexes of points that belongs to a component
In this case it's three connected components, but what if it's more, as well how I define sv.cellColors
? Depending of what the constraints are set?
Thank you so much
from vedo.
sorry I don't understand your question!
from vedo.
I'm trying to segment my mesh depending on the connected components I obtained,
each list above represent a region and I would like to color it unique color.
from vedo.
You can try with something like:
import numpy as np
from vedo import *
settings.interpolateScalarsBeforeMapping = False # avoid full interpolation
s1 = Sphere(res=12).lw(1)
#some code for extracting connected components
groups = [[0, 152, 162, 172, 182, 192, 202, 212, 222, 232, 2, 12, 22, 32, 42, 52, 62, 72, 82, 92, 102, 112, 122, 132, 142],
[1, 41, 31, 21, 11, 241, 231, 221, 211, 201, 191, 181, 171, 161, 151, 141, 131, 121, 111, 101, 91, 81, 71, 61, 51],
[3, 13, 23, 33, 43, 53, 63, 73, 83, 93, 103, 113, 123, 133, 143, 153, 163, 173, 183, 193, 203, 213, 223, 233, 234, 4, 14, 24, 34, 44, 54, 64, 74, 84, 94, 104, 114, 124, 134, 144, 154, 164, 174, 184, 194, 204, 214, 224, 225, 235, 5, 15, 25, 35, 45, 55, 65, 75, 85, 95, 105, 115, 125, 135, 145, 155, 165, 175, 185, 195, 205, 215, 216, 226, 236, 6, 16, 26, 36, 46, 56, 66, 76, 86, 96, 106, 116, 126, 136, 146, 156, 166, 176, 186, 196, 206, 207, 197, 187, 177, 167, 157, 147, 137, 127, 117, 107, 97, 87, 77, 67, 57, 47, 37, 27, 17, 7, 237, 227, 217, 218, 208, 198, 188, 178, 168, 158, 148, 138, 128, 118, 108, 98, 88, 78, 68, 58, 48, 38, 28, 18, 8, 238, 228, 229, 219, 209, 199, 189, 179, 169, 159, 149, 139, 129, 119, 109, 99, 89, 79, 69, 59, 49, 39, 29, 19, 9, 239, 240, 10, 20, 30, 40, 50, 60, 70, 80, 90, 100, 110, 120, 130, 140, 150, 160, 170, 180, 190, 200, 210, 220, 230]]
pts = s1.points()
pts0 = Points(pts[groups[0]], r=10, c='r')
pts1 = Points(pts[groups[1]], r=10, c='g')
pts2 = Points(pts[groups[2]], r=10, c='b')
ptdata = np.zeros_like(pts)
ptdata[groups[0]] = 0
ptdata[groups[1]] = 1
ptdata[groups[2]] = 2
s1.addPointArray(ptdata, "groupnumber")
# color mesh using vertex points
s1.cmap('jet_r', "groupnumber")
# map point data to cells (mesh faces) and color those
s2 = s1.clone() # make a copy
s2.mapPointsToCells().cmap('jet_r', on='cells')
show([(s1,pts0,pts1,pts2), s2], N=2, axes=1)
from vedo.
@marcomusy I'm really appreciating your assitance, thank you so much,
One more idea if you please, what regarding more than 3 groups, in other word, ok. I'll be making a for loop
dependable on len(groups)
but my problem is how to assign different colors, how I shall assign these with different c
: pts0 = Points(pts[groups[0]], r=10, c='r')
I was trying for the points(not regions, something like this:
# keys = ['r','black','blue','white','green','purple']
# pt = []
# pts = []
#
# for i in component:
# print(i)
# for s, key in enumerate(keys):
# print(key)
# pt.append(Points(pts, c=key, r=7))
# show(s, pt)
It's not giving correct results as well, :(
but this assigns only for 5 colors, some one suggests to make hexcolors
but also didn't worked, since I'm getting only the last color visualized, I'm not getting what I'm missing,
I don't want to depend on stick number, (5 here, or 3 in your example) instead I would like it to be dependable on the problem.
Much appreciated again.
from vedo.
this works for me:
from vedo import *
import numpy as np
keys = ['r','black','blue','white','green','purple']
vpt = []
components= [0]
for i in components:
for j, key in enumerate(keys):
pts = np.random.rand(50, 3) + j
vpt.append(Points(pts, c=key, r=7))
show(*vpt, "some other stuff", axes=1).close()
from vedo.
Sorry, I'm again re- asking after getting some trouble with this;
And again I'll try to clarify what I want,
I have a dynamic number of connected components, and I would like to color each region with different color, just like what this issue is opened for, but instead of only 3 colors, I might have more than 50 regions to color!
is it possible??
for example I have:
14
[[0, 71, 70, 223, 184, 186, 236, 208, 193, 207, 194, 189, 190, 195, 206, 213, 209, 205, 215, 174, 339, 212, 197, 179, 177, 220, 286, 221, 204, 329, 258, 274, 255, 246, 268, 265, 334, 245, 267, 264, 271, 248, 256, 251, 244, 249, 275, 270, 58, 313, 314, 316, 164, 345, 319, 61, 259, 202, 253, 203, 328, 257, 247, 272, 266, 262, 335, 263, 336, 240, 241, 250, 276, 269, 59, 312, 315, 317, 163, 346, 320, 60, 260, 201, 254, 252, 243, 200, 311, 308, 318, 273, 309, 310, 199, 198, 239, 56, 116, 118, 119, 128, 122, 323, 347, 288, 113, 287, 325, 322, 121, 120, 324, 154, 114, 348, 289, 178, 180, 187, 196, 211, 210, 214, 171, 340, 238, 99, 337, 106, 293, 150, 52, 51, 321, 123, 117, 57, 242, 50, 151, 292, 109, 338, 98, 237, 43, 69, 291, 65, 75, 127, 342, 157, 112, 153, 155, 152, 294, 295, 296, 115, 156, 126, 341, 74, 66, 290, 68, 218, 172, 282, 107, 283, 108, 42, 344, 173, 40, 41, 67, 54, 146, 149, 148, 297, 145, 147, 162, 143, 161, 159, 124, 130, 100, 299, 298, 77, 300, 301, 62, 63, 168, 165, 226, 182, 216, 222, 181, 217, 224, 183, 185, 235, 188, 191, 192, 64, 53, 343, 176, 47, 111, 160, 110, 281, 46, 175, 219, 44, 45, 48, 73, 72, 125, 129, 103, 304, 305, 76, 303, 302, 285, 169, 170, 104, 78, 105, 279, 81, 82, 229, 85, 102, 280, 326, 133, 83, 80, 327, 131, 227, 228, 86, 132, 79, 231, 306, 135, 89, 332, 278, 232, 91, 92, 331, 90, 88, 137, 138, 94, 333, 277, 233, 307, 136, 93, 84, 230, 87, 134, 139, 140, 95, 330, 234, 96, 97, 167, 166, 284, 101, 225, 142, 144, 141, 158, 23, 25, 261, 26, 36, 35, 34, 24, 9, 49, 55, 16, 19, 29, 21, 8, 1, 2, 14, 11, 33, 4, 5, 7, 39, 32, 10, 37, 38],
[3],
[6],
[12],
[13],
[15],
[17],
[18],
[20],
[22],
[27],
[28],
[30],
[31]]
I have here 14 regions, and as you notice, some vertices are single in the region!
I appreciate your assistance
from vedo.
is it possible??
yes, obviously!
you can use a color map to transform a continuos scalar into a rgb color with
rgb_col = colorMap(value, name=="jet", vmin=0, vmax=123)
from vedo.
from vedo.
show([(s1,pts0,pts1,pts2), s2], N=2, axes=1)
Please, for a mesh I tried, where I got also three connected components, I tried the quoted reply as it is, but the Visualization is not proper and same, it differs between the two, the attached shows what I mean,
Also regarding the last reply from you, what should value
means? since I tried it to be for components, it gives an error, tried it in a for loop for each of the connected component, it also didn't give any thing.
from vedo.
value
is a real nr between vmin and vmax
sorry, i have no idea of what "connected components" is, your questions are not clear at all.
from vedo.
from vedo.
Related Issues (20)
- How to add the slider? HOT 1
- How to load multiple Volumes in 1 3D interactive plane HOT 4
- Segmentation and Visualization of CT Scan Structures Based on Density in Vedo HOT 4
- Overlap on inside of Tube HOT 1
- Mesh cut with cut_with_box results in non water tight mesh HOT 2
- Optimize Loading and Visualization of Multiple .nii.gz Segments in Vedo HOT 1
- Issue with `mask` Function Example and Request for Assistance with `hide_voxels()` Function HOT 8
- How to flatten mesh to 2D and get its internal and external boundaries? HOT 8
- Vedo only render the change when I move my mouse on the screen HOT 6
- Vedo and torch.multiprocessing HOT 1
- How to change ImageScalars from volume.slice_plane() to be turned to image (numpy) ? HOT 4
- How to integrate interactive volume objects on Webpage? HOT 1
- Running vedo in a Docker container not working. HOT 2
- (x,y) coordinate format not working on LegendBox HOT 1
- test extract_cells_by_type() failing on 32-bit arches: Expecting a numpy.int32 array, got int64 instead. HOT 2
- Close an extruded mesh with a cover HOT 4
- Access faces of a mesh based on their ouput colour HOT 3
- DistanceTool Not Working HOT 2
- plane normal HOT 3
- Adding item to Group HOT 2
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from vedo.