Reading PLY file with color - vtk

I have a PLY file (exported from Solidworks inc. vertex colors), which I want to visualize using vtk.
The header information of the file shows that it contains some color information:
ply
format binary_little_endian 1.0
comment SOLIDWORKS generated,length unit = Millimeter
element vertex 8927
property float x
property float y
property float z
element face 17436
property uchar red
property uchar green
property uchar blue
property uchar alpha
property list uchar int vertex_indices
end_header
I read the file using vtkPLYReader, but somehow I do not see different colors on the model. The whole model is represented as white. If I open the file in MeshLab the colors are there.
dataPath = 'model.PLY'
reader = vtk.vtkPLYReader()
reader.SetFileName(dataPath)
polyDataMapper = vtk.vtkPolyDataMapper()
polyDataMapper.SetInputConnection(reader.GetOutputPort())
polyDataMapper.ScalarVisibilityOff()
polyDataMapper.Update()
actor = vtk.vtkActor()
actor.SetMapper(polyDataMapper)
actor.GetProperty().SetOpacity(1.0)
actor.Modified()
renderer.AddActor(actor)
Any suggestion, how could I visualize it with colors?

Just remove this line
polyDataMapper.ScalarVisibilityOff()
or rather explicitly write
polyDataMapper.ScalarVisibilityOn()

Related

How to map discrete colours in a Plotly Sunburst chart in r

I am very new to using plotly in rstudio and have come up against a problem with mapping discrete colours (stored as hex codes in the field color) to each of the slices in my ids field.
I have included my code below:
df %>%
plot_ly(
color = I("black"),
marker = list(colors = ~color)) %>%
add_trace(ids = df$ids,
labels = df$labels,
parents = df$parents,
type = 'sunburst',
maxdepth = -1,
domain = list(column = 0)) %>%
layout(sunburstcolorway = df$color)
This is the resulting sunburst diagram I get using this code, which is obviously not ideal:
Ideally the first four levels would have the same colour, and then different hex colour codes are used for slices that are labelled "Poor","Moderate","GwC" or "Good".
A csv file of my data frame used above is available here.
I finally managed to nut out how to map my colour field to the background colours on the sunburst chart - have updated the code in original post. All that was required was to insert the following code segment:
plot_ly(
marker = list(colors = ~color))
Below is the output chart:

How to use icon font with Jetpack Compose?

in before xml in TextView we have
holder.binding.iconInfo.text = "&#x${iconValue}"
and set out icon font to it with typeface dose anyone can help same thing but with jetpack compose
The specific syntax you mention that can be used with TextViews is due to the fact that XML is used when defining layouts. That is an XML numeric character entity that specifies a character with its unicode value in hexadecimal notation.
So it is not related to TextViews, layouts, fonts or icons.
If you want to do the same with a String in Kotlin and the character value is dynamic, you can do something like this
val text = "${Char(iconValue)}"
In Compose a custom font can be defined either as part of your Theme -> Typography and then used as text style or you can define it directly like this
val fontFamily = FontFamily(
// If you have the font in resources
Font(R.font.my_font_normal, weight = FontWeight.Normal),
Font(R.font.my_font_bold, weight = FontWeight.Bold),
Font(R.font.my_font_italic, weight = FontWeight.Normal, style = FontStyle.Italic),
// If you are loading the font at runtime from a file
Font(File(...), weight = FontWeight.Normal),
// ...
)
// Use with Text composable
Text(text = text, fontFamily = fontFamily)

How do I carry over identical texture mapping when exporting to DAE?

I am able to open a 3DS file in MeshLab and when I export to Collada DAE format the textures are visible but they are not being projected onto the mesh in the same way as the preview in MeshLab. For example, the front/back faces of a cube would have the proper texture (suppose it's a polka dot) but the top and bottom have a striped look. How can I apply a single texture and have it appear as intended on all faces, like the imported model before I convert it?
This problem is a result of the end software being used to view the DAE file. It's not a problem with MeshLab.
For example, if loading the file into Away3D be sure to handle the texture materials using the TextureMaterial class instead of the simpler SinglePassMaterialBase such as what you might find in their example code. Here is what I use now, and it displays texture properly:
var material:TextureMaterial = cast(asset, TextureMaterial);
material.ambientColor = 0xffffff;
material.lightPicker = _lightPicker;
material.shadowMethod = new FilteredShadowMapMethod(_light);
material.lightPicker = _lightPicker;
material.gloss = 30;
material.specular = 1;
material.ambient = 1;
material.repeat = true;

Get pixel data from Graphics object in Codename One

I'm trying to implement the Gaussian blur filter on Graphics object, but I can't find function for get pixel information or transform Graphics object to byte array (with RGB data).
That isn't supported since hardware accelerated surfaces might not provide that information.
However, you can do something else. Just paint the current form onto a mutable image and then just get the RGB of the mutable image which you can then use to create a new Image from an RGB e.g. something close to this:
Display d = Display.getInstance();
Image img = Image.createImage(d.getDisplayWidth(), d.getDisplayHeight());
Graphics g = img.getGraphics();
d.getCurrent().paintBackgrounds(g);
d.getCurrent().paintComponent(g, false);
int[] bufferArray = img.getRGB();
// blur...
Image blurredImage = Image.createImage(bufferArray, img.getWidth(), img.getHeight());

OpenGL glColorPointer renders black

Here is the breakdown: I load a model from an obj file and store into buffers as follows :vbo for vertexes, ibo for indexes , vao for state and num_indices an int with total indices number. To get the model color I exported a separate off file and extracted color information per vertex and I have an array with 4 values for each vertex so the size of the array is vertexno*4. My draw function looks like this.
glUniformMatrix4fv(location_model_matrix,1,false,glm::value_ptr(model_matrix));
glUniformMatrix4fv(location_view_matrix,1,false,glm::value_ptr(view_matrix));
glUniformMatrix4fv(location_projection_matrix,1,false,glm::value_ptr(projection_matrix));
//glUniform4f(location_object_color,1,1,1,1);
glBindVertexArray(mesh_vao);
glEnableClientState( GL_COLOR_ARRAY );
glEnableClientState( GL_VERTEX_ARRAY );
glColorPointer( 4, GL_FLOAT, 0, colors );
glDrawElements(GL_TRIANGLES,mesh_num_indices,GL_UNSIGNED_INT,0);
And the model renders black. I also have some cubes drawn in the draw function which I color using glUniform4f(location_object_color,rgba) and if I uncomment then the loaded mesh will take the same color as the last drawn cube.
In my constructor I have something like this:
glClearColor(0.5,0.5,0.5,1);
glClearDepth(1);
glEnable(GL_DEPTH_TEST);
gl_program_shader = lab::loadShader("shadere\\shader_vertex.glsl", "shadere\\shader_fragment.glsl");
location_model_matrix = glGetUniformLocation(gl_program_shader, "model_matrix");
location_view_matrix = glGetUniformLocation(gl_program_shader, "view_matrix");
location_projection_matrix = glGetUniformLocation(gl_program_shader, "projection_matrix");
location_object_color = glGetUniformLocation(gl_program_shader, "object_color");
If need be I can provide my shader_vertex and shader_fragment , I considered it to be a problem but im not so sure so if anyone knows why my model isn't being colored please throw a hand.

Resources