De-indexing Collada - c

How de-indexing the triangles of my collada mesh?. My goal is get something like:
<triangles material = "mat0" count ="12">
<input semantic = "VERTEX" source = "#mesh1"/>
<input semantic = "NORMAL" source = "#norm1"/>
<p>
0 0 1 1 4 4 3 3 5 5 7 7 6 6 8 8 .... <- same indices
</p>
</triangles>
it's this possible? I use C language and OpenGL API. I want to use VBO.

I still use COLLADA Refinery to fix my mesh data :
http://collada.org/mediawiki/index.php/COLLADA_Refinery
I have a script that goes through all my collada files doing different operations. It might have the operations you are looking for. Note that the last release was in 2007.
Full list of conditioners :
http://collada.org/mediawiki/index.php/Portal:Conditioners_directory
Deindexer
http://collada.org/mediawiki/index.php/Deindexer_conditioner
Rearranges vertices indexes so that each Vertices will reference the
corresponding Position, Normal, Texcoord with the same index number.
The size of source for position, normal, and texcoord might increase.

With meshtool you can run the following:
meshtool --load_collada file.dae
--normalize_indices
--save_collada file-normalized.dae

Related

CNN with RGB input and BW binary output

I am a beginner to deep learning and I am working with Keras built on top of Tensorflow. I am trying to using RGB images (540 x 360) resolution to predict bounding boxes.
My labels are binary (black/white) 2 dimensional np array of dimensions (540, 360) where all pixels are 0 except for the box edges which are a 1.
Like this:
[[0 0 0 0 0 0 ... 0]
[0 1 1 1 1 0 ... 0]
[0 1 0 0 1 0 ... 0]
[0 1 0 0 1 0 ... 0]
[0 1 1 1 1 0 ... 0]
[0 0 0 0 0 0 ... 0]]
There can be more than one bounding box in every picture. A typical image could look like this:
So, my input has the dimension (None, 540, 360, 3), output has dimensions (None, 540, 360) but if I add an internal array I can change the shape to (None, 540, 360, 1)
How would I define a CNN model such that my model could fit this criteria? How can I design a CNN with these inputs and outputs?
You have do differentiate between object detection and object segmentation. While both can be used for similar problems, the underlying CNN architectures look very different.
Object detection models use a CNN classification/regression architecure, where the output refers to the coordinates of the bounding boxes. It's common practice to use 4 values belonging to vertical center, horizontal center, width and height of each bounding box. Search for Faster R-CNN, SSD or YOLO to find popular object detection models for keras. In your case you would need to define a function that converts the current labels to the 4 coordinates I mentioned.
Object segmentation models commonly use an architecture referred to as encoder-decoder networks, where the original image is scaled down and compressed on the first half and then brought back to it's original resolution to predict a full image. Search for SegNet, U-Net or Tiramisu to find popular object segmentation models for keras. My own implementation of U-Net can be found here. In your case you would need to define a custom function, that fills all the 0s inside your bounding boxes with 1s. Understand that this solution will not predict bounding boxes as such, but segmentation maps showing regions of interest.
What is right for you, depends on what precisely you want to achieve. For getting actual bounding boxes you want to perform an object detection. However, if you're interested in highlighting regions of interest that go beyond rectangle windows a segmentation may be a better fit. In theory, you can use your rectangle labels for a segmentation, where the network will learn to create better masks than the inaccurate segmentation of the ground truth, provided you have enough data.
This is a simple example of how to write intermediate layers to achieve the output. You can use this as a starter code.
def model_360x540(input_shape=(360, 540, 3),num_classes=1):
inputs = Input(shape=input_shape)
# 360x540x3
downblock0 = Conv2D(32, (3, 3), padding='same')(inputs)
# 360x540x32
downblock0 = BatchNormalization()(block0)
downblock0 = Activation('relu')(block0)
downblock0_pool = MaxPooling2D((2, 2), strides=(2, 2))(block0)
# 180x270x32
centerblock0 = Conv2D(1024, (3, 3), padding='same')(downblock0_pool)
#180x270x1024
centerblock0 = BatchNormalization()(center)
centerblock0 = Activation('relu')(center)
upblock0 = UpSampling2D((2, 2))(centerblock0)
# 180x270x32
upblock0 = concatenate([downblock0 , upblock0], axis=3)
upblock0 = Activation('relu')(upblock0)
upblock0 = Conv2D(32, (3, 3), padding='same')(upblock0)
# 360x540x32
upblock0 = BatchNormalization()(upblock0)
upblock0 = Activation('relu')(upblock0)
classify = Conv2D(num_classes, (1, 1), activation='sigmoid')(upblock0)
#360x540x1
model = Model(inputs=inputs, outputs=classify)
model.compile(optimizer=RMSprop(lr=0.001), loss=bce_dice_loss, metrics=[dice_coeff])
return model
The downblock represents the block of layers which perform downsampling(MaxPooling2D).
The centerblock has no sampling layer.
The upblock represents the block of layers which perform up sampling(UpSampling2D).
So here you can see how (360,540,3) is being transformed to (360,540,1)
Basically, you can add such blocks of layers to create your model.
Also check out Holistically-Nested Edge Detection which will help you better with the edge detection task.
Hope this helps!
I have not worked with keras but I will provide a solution approach in more generalized way which can be used on any framework.
Here is full procedure.
Data preparation: I know your labels are edges of boxes which will also work but i will recommend that instead of edges you prepare dataset marking complete box like given in sample (I have marked for two boxes). Now your dataset have three classes (Box,Edges of box and background). Create two lists, Image and label.
Get a pre-trained model (RESNET-51 recommended) solver and train prototxt from here, Remove fc1000 layer and add de-convolution/up-sampling layers to match your input size. use paddding in first layer to make it square and crop in deconvolution layer to match input output dimensions.
Transfer weights from previously trained network (Original) and train your network.
Test your dataset and create bounding boxes using detected blobs.

Plotting irregularly-spaced arrays in gnuplot 5.x

gnuplot 5.x now supports arrays, but there seems to be no way to plot, or fit, to an irregularly-spaced set of data, if it is not provided in an external file. What I would like to see is the ability to plot "y vs x":
array z[8]=[0,1,2,3,4,5,6,6.4]
array f[8]=[0.468,0.405,0.342,0.279,0.216,0.153,0.090,0.064]
plot z,f
or even
plot [3,3],[0,0.25] w lines
which would, for example, provide a handy vertical marker line at x=3 without needing to resort to arrows without heads:
plot '+' using (3):(0):(0):(0.25) with vectors nohead
One can achieve the plotting in this awkward-looking way:
plot sample [j=1:|x|] '+' using (x[j]):(y[j])
but, unfortunately, the same syntax is not recognized by the fit command.
The only way I figured so far is to write the data to a virtual file (a data block), and use it as input to both plot and fit commands:
set print $DATA
print sprintf("# z\tf") ## header line, overwrite old content if any
set print $DATA append ## append data lines
do for [j=1:|z|] {
print sprintf("%f\t%f",z[j],f[j])
}
unset print
y(x)=m*x-y0
y0=0.25
m=1
fit y(x) $DATA via m,y0
plot $DATA t 'data',y(x) w lines t 'fit'
Is there a better way? Or can someone explain to me why such an obvious task is not a part of the standard plot/array implementation? It certainly would be one of the first things on my wish list.
What describe is exactly the purpose of data blocks:
$DATA <<EOD
0 0.468
1 0.405
2 0.342
3 0.279
4 0.216
5 0.153
6 0.090
6.4 0.064
EOD
y(x)=m*x-y0
y0=0.25
m=1
fit y(x) $DATA via m,y0
plot $DATA t 'data',y(x) w lines t 'fit'
Thanks Christoph for extensive help. It has emerged that data block syntax together with the appropriate "using" options would achieve what I had set out to do. Inline specification for a data block is perfectly compact, and the pre-processing can be replaced for both plot... and fit... with identical syntax:
$DATA <<EOD
0 0.468
1 0.405
2 0.342
3 0.279
4 0.216
5 0.153
6 0.090
6.4 0.064
EOD
y(x)=m*(x-x0)**2+y0
y0=0.9
m=-0.1
x0=4
fit y(x) $DATA using ($1):($1)*($2) via m,x0,y0
plot $DATA using ($1):($1)*($2) t 'data',y(x) w lines t 'fit'
To plot the data stored in arrays as it is, you can write it in the following way (I tried this in version 5.4).
array z[8]=[0,1,2,3,4,5,6,6.4]
array f[8]=[0.468,0.405,0.342,0.279,0.216,0.153,0.090,0.064]
plot z using (z[$0+1]):(f[$0+1])
At first glance, it seems that (z[$0+1]) in using can be replaced by 1, but in the version I tried, I had to do this.

Exporting ARIMA-regression forecasts

I'll be grateful if you can answer this. I fit a regression-ARIMA model as
'm1<-arima(y1,order=c(0,1,1),xreg=x1)'
Standard command for ARIMA with regressors.
Then I use it to predict ahead:
'f1<-predict(m1,newxreg=x2,n.ahead=5)'
standard stuff
The problem appears next, where I get this output (focusing on the part that matters):
[126] 0.160095040 0.350650026 0.281973859 -0.161599717 0.305046264
$se
Time Series:
Start = 131
End = 135
Frequency = 1
[1] 0.2268524 0.2283935 0.2299241 0.2314447 0.2329553
I'd overlook that it repeats the entire series, which I'm not interested in; my problem is that I can't export the predictions! When I submit
'write.csv(f1,"out.csv")'
I get
Error in data.frame(pred = c(0.303546011854172, 0.240057038087077, 0.125706531559436, : arguments imply differing number of rows: 130, 5
As for the forecasts, the vector f1 appears of length 2, with f1[1] being the 130 original observations, and f1[2] being the 5 forecasts! (Instead of f1[1] being the forecast of the 1st period ahead, f1[2] the forecast of the 2nd period, etc)
Any ideas of what's going on and what can I do about it?
And to intrique you even more, the problem only appears when I use regressors! Everything works well if I only have ARIMA!
Any help is much appreciated!

Adding/generating content automatically in Vim

I have a huge list of numbers and I would like to add content on the end of each line. It's something like this:
Before:
123123
123123
13234
124125
12634
5234
After:
123123, 1
123123, 2
13234, 3
124125, 4
12634, 5
5234, 6
A couple of points:
I know that :range s/oldpattern/newpattern/ will substitute the oldpattern by the new one.
I know that for i in range(begin, end) | something | endfor can generate those extra numbers.
However, I don't know if it's possible to combine them to do what I want (or if there's a different way to do it). Does anybody knows how can I add those extra values automatically? I'm quite sure that it's possible using Vim, but I don't know how.
You can do this by visually selecting the area then typing
:s/$/\=', '.(line('.')-line("'<")+1)<CR>
(range is added automatically when you type : from visual mode). Visual mode is needed to get line("'<") thing, if you are fine with typing line number in place of it use any range.
I'd do
:%!nl
:%s/\v^\s*(\d+)\s+(.*)$/\2, \1/g
nl will (by default) skip numbering empty lines
Or as a oneliner
:exec "%!nl"|%s/\v^\s*(\d+)\s+(.*)$/\2, \1/g
:%!awk '{print $0", "NR}'
or
:%!perl -lpe '$_.=", $."'

Multiple raw input buffer

Is there a way to have one raw input buffer per device?
So I would like to have a buffer for mouse and another one for keyboard.
Is it possible?
Yes, try SetWindowsHookEx. You will have to convert WM_KEY* messages to WM_CHAR yourself, though.
The answer to your question is YES
The RAWINPUTDEVICE struct permits this via usUsagePage and usUsage
usUsagePage is a value for the type of device (this is a partial list below). 1 is for 'generic desktop controls' and covers all the usual input devices. The usUsage value specifies the device within the 'generic desktop controls' group.
1 - generic desktop controls // we use this
2 - simulation controls
3 - vr
4 - sport
5 - game
6 - generic device
7 - keyboard
8 - LEDs
9 - button
usUsage values when usUsagePage is 1:
0 - undefined
1 - pointer
2 - mouse
3 - reserved
4 - joystick
5 - game pad
6 - keyboard // we use this
7 - keypad
8 - multi-axis controller
9 - Tablet PC controls
I wrote this article on Code Project that may be helpful.

Resources