Drawing a graph with some properties displayed with Boost Graph Library - boost-graph

everyone. I have been using Boost Graph Library but it's quite difficult to me. Recently, I have tried to draw the following graph (I used .dot file to display coz I don;t have enough reputation to attach a picture, sorry for any inconvenience caused)
enter code here
graph{
0[label = "Prof Nachiket", color = blue];
1[label = "Nick", color = red];
2[label = "Lam", color = green];
0 -- 1[label = "Supervisor"];
0 -- 1[label = "Supervisor"];
1 -- 2[label = "Co-worker" ];
}
And then turn it into a picture with Graphviz. However, I got no idea how to add information such as label, color into edges of graph. In other words, I have a little or no idea how to draw above graph by using Boost Graph Library. Could anyone help me out? Thanks a lot
Best Regards
Nick Ng

NEW ANSWER
Its a dube, see
How to print a boost graph in graphviz with one of the properties displayed?
boost graph library - minimal example of vertex colors and graphviz output
http://www.boost.org/doc/libs/1_54_0/libs/graph/doc/write-graphviz.html
How to print a graph in graphviz with multiple properties displayed
drawing custom BGL graph with graphviz
C++ Boost Graph Library: outputting custom vertex properties
OLD ANSWER:
There are many resources online which specifies how to draw advanced graphs using Graphviz. Here are some which I have found useful in the past:
www.graphviz.org/pdf/dotguide.pdf‎
www.graphviz.org/content/attrs
www.graphviz.org/content/output-formats
www.graphviz.org/doc/info/shapes.html
http://graphviz-dev.appspot.com/
The last link is an online render, very useful if you dont have graphviz on your machine.
For your specific question here's a simple example using colored edges and labels:
Dot:
graph{
0 [label = "Prof Nachiket", color=blue shape=ellipse ];
1 [label = "Nick", color = red shape=Mdiamond];
2 [label = "Lam", color = green shape=diamond];
0 -- 1[label = "Supervisor" color=pink];
1 -- 2[label = "Co-worker" color=red penwidth=2];
}
Img:

Related

Measure vertical distance of binarized image (Open CV) C++

So this should be straight forward but I a not very familiar with OpenCV.
Can someone suggest a method to measure the distance in pixels (red line) as shown in the image below? Preferably it had some options like width of measurement (as demonstrated at the end and begining of the red line) or something of sorts. This kind of measurement is very common in software like ImageJ, I can imagine it should be somewhat trivial to do it in OpenCV.
I would like to take several samples accros the image width as well.
Greets
I am using openCV and learning about it
Your task is quite simple.
optional smoothing (Gauss filter) - you have to experiment with your data to see if it helps
edge detection (will transform image to lines representing edges) - for example cv::Canny
Hough transform to detect lines - openCV.
Find two maximum values (longest lines) in Hough transform
you will have two questions of straight lines, then you can use this information to calculate distance between them
Note that whit this approach image doesn't have to be straight. You will have line equations which you have to manipulate in smart way. If those two lines are parallel this there is simple formula to get distance between them. If they are not perfectly parallel then you have to take this int account and use information about image area to get average distance.
A simple way to find the width of the channel would be the following:
distance = []
h = img.shape[0]
for j in range(img.shape[1]):
line_top = 0
line_bottom = img.shape[0]
found_top = False
found_bottom = False
for i in range(h):
if img[i,j,0] > 0 and not found_top:
line_top = i
found_top = True
if img[h-i-1,j,0] > 0 and not found_bottom:
line_bottom = h-i
found_bottom = True
if found_top and found_bottom:
distance.append(line_bottom-line_top)
break
But this would cause the distance to take into acount the very small white speckles.
To solve this there are several options:
Preprocess the image using opencv morphological transformation.
Preprocess the image using opencv gaussian filter or similar.
Update the code to use a larger window.
Another solution would be to apply opencv's findContours.

how to remove vertex , edge or face from CGAL::Linear_cell_complex_for_combinatorial_map

I'm creating an application using qt creator which read .off files as CGAL::Linear_cell_complex_for_combinatorial_map and preview it
I want to make operations on the read mesh such as removing vertix,edge or face and restore it .
I created a loop to access darts :
Dart_handle dh;
for (LCC_3::Dart_range::iterator it=lcc.darts().begin(),
itend=lcc.darts().end(); it!=itend; )
{
dh=it++;
if ( it!=itend && it==lcc.beta<2>(dh) ) ++it;
}
any help or usefull links to simplify mesh or removing vertices , edges or faces ?
I appreciate any help
You can use the remove_cell operation. The method is templated by the dimension of the cell to remove: 0 for vertices, 1 for edges, 2 for faces...
See the doc here and the example there.

Can't render Quake 3 bsp format

I am writing a loader and a renderer of *.bsp Quake 3 files for my 3D engine. I am supporting the format version 46 (0x2e). Everything is rendered well untill I am using very simple maps. The geometry of simple maps renders correctly both under my engine and the renderer that I found in the Internet (at http://www.paulsprojects.net/opengl/q3bsp/q3bsp.html). Here is the screenshot:
I tried rendering more complicated maps (from: http://lvlworld.com/) with my renderer and a renderer that I found to compare the results. And both renderers suffer from a problem that there are holes in the scene (missing triangles here and there).
I have no clue what my be causing those problems as I checked the maps and they are all of the same version. Has anybody encountered this problem?
EDIT: Some of the very complicated maps render correctly. It confuses me even more :).
The creator of this bsp loader made something wrong. I got fixed it.
Simply edit LoadData function, and make all face data ( except meshes and patches ) into one array and render it. Works for me, no more "holes". Here's piece of code:
int currentFace = 0;
for( int i = 0; i < facesCount; i++ ) {
if( faceData[i].type != SW_POLYGON )
continue;
m_pFaces[i].texture = faceData[i].texture;
m_pFaces[i].lightmapIndex = faceData[i].lightmapIndex;
m_pFaces[i].firstVertexIndex = faceData[i].firstVertexIndex;
m_pFaces[i].vertexCount = faceData[i].vertexCount;
m_pFaces[i].numMeshIndices = faceData[i].numMeshIndices;
m_pFaces[i].firstMeshIndex = faceData[i].firstMeshIndex;
f_bspType[i].faceType = SW_FACE; // Custom one.
f_bspType[i].typeFaceNumber = currentFace;
currentFace++;
}

Can you apply colour maps to volume renders?

Every example I have seen only renders in greyscale.
Is there a way to map scalar volumes in voxels to colours? ( similar to vtkColorTransferFunction in VTK for example?)
If there is no support for this out of the box, how difficult would it be for us to add that capability?
So far, only min and max colors are supported (lesson 15).
...
r.onShowtime = function() {
v.minColor = [0, 0.06666666666666667, 1];
v.maxColor = [0.5843137254901961, 1, 0];
};
...
You could also use a custom labelmap/color table as a hack for now (lesson 11).
There is no easy mechanism to support it right now but this is on the TODO list and should not be too hard to implement.
Please feel free to contribute to XTK on github, this would be a very useful addition!
https://github.com/xtk/X
Thanks

convert an rgb image into a matrix using C++ and Cimg library

I have this project in blind source seperation where I need to represent a RGB image in a matrix using Cimg. but I can't actually understand how to use Cimg.. I've looked through the documentation in
But there are TOO many functions and I wasn't able to know which one to use! really too many of them. I have never used Cimg, so if anyone could explain to me what should my procedure be please do!
I am programming with C++ and using eclipse.
Thanks!
First define your image :
CImg<float> img(320,200,1,3); // Define a 320x200 color image (3 channels).
Then fill it with your data :
cimg_forXYC(img,x,y,c) { // Do 3 nested loops
img(x,y,c) = pixel_value_at(x,y,c);
}
Then you can do everything you want with it.
img.display("Display my image");
when c==0, you will fill the red channel of your image, when c==1, the green one and when c==2 the blue one. Nothing really hard.
I have experimented a lof of image processing libraries, and CImg is probably one of the easiest to use. Look at the provided example files (folder CImg/examples/) to see how the whole thing is working (particularly CImg/examples/tutorial.cpp).
Getting started with any 3rd party library, I find it useful to start with a tutorial, like this one: CImg Tutorial
Especially if you are new to C++/programming in general.
Don't get frustrated with the wealth of the interface or magnitude of code. Stick to what you are looking for and let Google be your friend.
To get you started, **get acquainted with the CImg class. Then advance as your need dictates...
If you're not forced with CImg, I suggest you to use DevIL, an example of a working code looks like:
ilLoad();
ILuint image = 0;
ilGenImages(1,&image);
if(!image)
{
// Error
}
ilBindImage(image);
if(!ilLoadImage("yourimage.png"))
{
// Error
}
// 4-bytes per pixel for RGBA
ILuint width = ilGetInteger(IL_IMAGE_WIDTH);
ILuint height = ilGetInteger(IL_IMAGE_HEIGHT);
unsigned char* data=width*height*4;
ilCopyPixels(0,0,0,width,height,1,IL_RGBA,IL_UNSIGNED_BYTE,data);
ilDeleteImages(1,&image);
image = 0;
// now you can use 'data' as a pointer to all your required data.
// You can access from data[0] up to data[ (width*height*4) - 1].
// First pixel's red value: data[0]
// Second pixel's green value: data[1 + (4 * 1)]
// Third pixel's alpha value: data[3 + (4 * 2)]
// Once you're done...
delete[] data;
data = 0;