opencv and c++ visual studio 2012 - c++

I have this code it work good.
When video length less than 1 minute and video size its 165 KB
When I change the video with other length 2 minute and size 15 MB OR another one same length with size 5 MB its show to me
project has stop working
this my code
# include "windows.h"
# ifdef _CH_
# pragma package < opencv >
# endif
# include "windows.h"
# ifndef _EiC
# include "cv.h"
# include "cvAux.h"
# include "highgui.h"
# include "cxcore.h"
# include < stdio.h >
# include < ctype.h >
# endif
// x?y?
int getpixel ( IplImage * image , int x , int y , int * h , int * s , int * v ) {
* h = ( uchar ) image -> imageData [ y * image -> widthStep + x * image -> nChannels ] ;
* s = ( uchar ) image -> imageData [ y * image -> widthStep + x * image -> nChannels + 1 ] ;
* v = ( uchar ) image -> imageData [ y * image -> widthStep + x * image -> nChannels + 2 ] ;
return 0 ;
}
//--------------------------------------------------------------------------------
int main ( int argc , char * * argv ) {
CvCapture * capture = cvCaptureFromAVI("a.avi") ;
IplImage * image = 0;
IplImage * HSV = 0 ;
/*
IplImage* img = cvLoadImage("greatwave.png", 1);
Mat mtx(img); // convert IplImage* -> Mat
*/
if ( argc == 1 || ( argc == 2 && strlen ( argv [ 1 ] ) == 1 && isdigit ( argv [ 1 ] [ 0 ] ) ) ) {
//capture = cvCaptureFromCAM ( argc == 2 ? argv [ 1 ] [ 0 ] - '0' : 0 ) ;
}
else if ( argc == 2 ) {
//capture = cvCaptureFromAVI ( argv [ 1 ] ) ;
}
if ( !capture ) {
fprintf ( stderr , "Could not initialize capturing.../n" ) ;
return - 1 ;
}
printf ( "Hot keys: /n" "/tESC - quit the program/n" ) ;
//Normal
cvNamedWindow ( "Normal" , CV_WINDOW_AUTOSIZE ) ;
//Condensation-------------------------------------------------
int DP = 2 ; //
int MP = 2 ; //
int SamplesNum = 300 ; //
CvConDensation * ConDens = cvCreateConDensation ( DP , MP , SamplesNum ) ;
//-----------------------------------------------------------------------
//Condensation-----------------------------------
CvMat * lowerBound ; //
CvMat * upperBound ; //
lowerBound = cvCreateMat ( 2 , 1 , CV_32F ) ;
upperBound = cvCreateMat ( 2 , 1 , CV_32F ) ;
//640*480
cvmSet ( lowerBound , 0 , 0 , 0.0 ) ;
cvmSet ( upperBound , 0 , 0 , 640.0 );
cvmSet ( lowerBound , 1 , 0 , 0.0 ) ;
cvmSet ( upperBound , 1 , 0 , 480.0 ) ;
cvConDensInitSampleSet ( ConDens , lowerBound , upperBound ) ;
//-----------------------------------------------------------------------
//------------------------------
for ( int i = 0 ; i < SamplesNum ; i++ ) {
ConDens -> flSamples [ i ] [ 0 ] += 320.0 ;
ConDens -> flSamples [ i ] [ 1 ] += 240.0 ;
}
//-----------------------------------------------------------------------
//----------------------------
ConDens -> DynamMatr [ 0 ] = 1.0 ;
ConDens->DynamMatr [ 1 ] = 0.0 ;
ConDens -> DynamMatr [ 2 ] = 0.0 ;
ConDens->DynamMatr [ 3 ] = 1.0 ;
//-----------------------------------------------------------------------
for ( ;; ) {
IplImage* frame = 0 ;
int c ;
int X , Y , XX , YY ;
int H , S , V ;
frame = cvQueryFrame ( capture ) ;
if ( !frame ) {
break ;
}
if ( !image ) {
image = cvCreateImage ( cvGetSize ( frame ) , 8 , 3 ) ;
image -> origin = frame -> origin ;
HSV = cvCreateImage ( cvGetSize ( frame ) , 8 , 3 ) ;
HSV -> origin = frame -> origin ;
}
cvCopy ( frame , image , 0 ) ;
cvCvtColor ( image , HSV , CV_BGR2HSV ) ;
//?---------------------------------------------------
for ( int i = 0 ; i < SamplesNum ; i++ ) {
X = ( int ) ConDens -> flSamples [ i ] [ 0 ] ;
Y = ( int ) ConDens -> flSamples [ i ] [ 1 ] ;
if ( X >= 0 && X <= 640 && Y >= 0 && Y <= 480 ) { //
getpixel ( HSV , X , Y , &H , &S , & V ) ;
if ( H <= 19 && S >= 48 ) { // //H<=19 S>=48
cvCircle ( image , cvPoint ( X , Y ) , 4 , CV_RGB ( 255 , 0 , 0 ) , 1 ) ;
ConDens -> flConfidence [ i ] = 1.0 ;
}
else {
ConDens -> flConfidence [ i ] = 0.0 ;
}
}
else {
ConDens -> flConfidence [ i ] = 0.0 ;
}
}
//--------------------------------------------------------------------------
//
cvConDensUpdateByTime ( ConDens ) ;
cvShowImage ( "Normal" , image ) ;
c = cvWaitKey ( 20 ) ;
if ( c == 27 ) {
break ;
}
}
//------------------------------------
cvReleaseImage ( &image ) ;
cvReleaseImage ( &HSV ) ;
cvReleaseConDensation ( &ConDens ) ;
cvReleaseMat ( &lowerBound ) ;
cvReleaseMat ( &upperBound ) ;
cvReleaseCapture ( &capture ) ;
cvDestroyWindow ( "Normal" ) ;
//---------------------------------------------
return 0 ;
}
# ifdef _EiC
main ( 1 , "condensation.cpp" ) ;
# endif
also when o comment this
for ( int i = 0 ; i < SamplesNum ; i++ ) {
X = ( int ) ConDens -> flSamples [ i ] [ 0 ] ;
Y = ( int ) ConDens -> flSamples [ i ] [ 1 ] ;
if ( X >= 0 && X <= 640 && Y >= 0 && Y <= 480 ) { //
getpixel ( HSV , X , Y , &H , &S , & V ) ;
if ( H <= 19 && S >= 48 ) { // //H<=19 S>=48
cvCircle ( image , cvPoint ( X , Y ) , 4 , CV_RGB ( 255 , 0 , 0 ) , 1 ) ;
ConDens -> flConfidence [ i ] = 1.0 ;
}
else {
ConDens -> flConfidence [ i ] = 0.0 ;
}
}
else {
ConDens -> flConfidence [ i ] = 0.0 ;
}
}
program work without do my idea of track object
i have windows 8
please comment if u dont understand some thing

I think that the problem is related to the declaration of IplImage *frame inside the for loop. When the size of your video length increases then, your memory gets full. Because you are continuously creating new frames inside the for loop without freeing the memory allocated to them.
You should declare IplImage *frame outside the for loop and then release the memory allocated to it outside the for loop.
ADVICE: Do not use old C-standards of OpenCV. Use the new C++ standards where you have to declare an image as Mat image. Then, you don't need to think about freeing memory because it does all the stuff itself.

Related

Power BI taking min value from Multiple text columns

I have these data
ID Daig 1 Daig 2 Daig 3 Daig 4
AA1 5 X X 2
AA2 X 1 4 X
AA3 7 3 X X
AA4 X X 2 6
AA5 X X X 3
I want to extract the min values from the columns ignoring the text(X)
I wrote the below DAX
Min Value = VAR V1 = IF(Data[Daig 1 ]="X",100,VALUE(Data[Daig 1 ]))
VAR V2 = IF(Data[Daig 2]="X",100,VALUE(Data[Daig 1 ]))
VAR V3 = IF(Data[Daig 3]="X",100,VALUE(Data[Daig 1 ]))
VAR V4 = IF(Data[Daig 4]="X",100,VALUE(Data[Daig 1 ]))
VAR temp = {V1, V2, V3, V4}
RETURN
MINX(Data,temp)
and it give error
Expected Output
This one is a measure:
Min Value =
MIN (
MIN (
MIN (
VALUE ( SUBSTITUTE ( SELECTEDVALUE ( Data[Daig 1] ), "X", 999 ) ),
VALUE ( SUBSTITUTE ( SELECTEDVALUE ( Data[Daig 2] ), "X", 999 ) )
),
VALUE ( SUBSTITUTE ( SELECTEDVALUE ( Data[Daig 3] ), "X", 999 ) )
),
VALUE ( SUBSTITUTE ( SELECTEDVALUE ( Data[Daig 4] ), "X", 999 ) )
)
And this approach i use as new calculated column:
Min_Value =
var __innerTab =
SELECTCOLUMNS(
GENERATE( VALUES(Data[ID])
, ROW(
"d1", IF(Data[Daig 1]="X",100,VALUE(Data[Daig 1])),
"d2", IF(Data[Daig 2]="X",100,VALUE(Data[Daig 2])),
"d3", IF(Data[Daig 3]="X",100,VALUE(Data[Daig 3])),
"d4", IF(Data[Daig 4]="X",100,VALUE(Data[Daig 4]))))
,
"min", min(min( Min([d1], [d2]),[d3]),[d4]))
return
__innerTab

Write the elements of an array to file where each element is on its own line in Fortran

I wrote some code to print out the elements of a 3d-array where each element of the array is printed to a new line on screen. That worked (see output below).
Can anyone help me write a format statement that can produce the same thing in a file? (i.e. using WRITE(*,1200) and 1200 FORMAT() etc)?
Here is my code:
PROGRAM test_3d_array
IMPLICIT NONE
integer :: matrix(3,3,3), i, j, k ! three dimensional real array
integer :: CORE, CON, ALPHA
CORE = 3
CON = 3
ALPHA = 3
!assigning some values to the array matrix
do i=1,ALPHA
do j = 1,CORE
do k = 1,CON
matrix(i, j, k) = i+j+k
end do
end do
end do
!display the values
do i=1,ALPHA
do j = 1, CORE
do k=1,CON
WRITE(*,*) "MATRIX (", i, ",", j, ",", k, ") = ", matrix(i,j,k)
end do
end do
end do
END PROGRAM test_3d_array
Here is the screen output that I want to reproduce in the file:
MATRIX ( 1 , 1 , 1 ) = 3
MATRIX ( 1 , 1 , 2 ) = 4
MATRIX ( 1 , 1 , 3 ) = 5
MATRIX ( 1 , 2 , 1 ) = 4
MATRIX ( 1 , 2 , 2 ) = 5
MATRIX ( 1 , 2 , 3 ) = 6
MATRIX ( 1 , 3 , 1 ) = 5
MATRIX ( 1 , 3 , 2 ) = 6
MATRIX ( 1 , 3 , 3 ) = 7
MATRIX ( 2 , 1 , 1 ) = 4
MATRIX ( 2 , 1 , 2 ) = 5
MATRIX ( 2 , 1 , 3 ) = 6
MATRIX ( 2 , 2 , 1 ) = 5
MATRIX ( 2 , 2 , 2 ) = 6
MATRIX ( 2 , 2 , 3 ) = 7
MATRIX ( 2 , 3 , 1 ) = 6
MATRIX ( 2 , 3 , 2 ) = 7
MATRIX ( 2 , 3 , 3 ) = 8
MATRIX ( 3 , 1 , 1 ) = 5
MATRIX ( 3 , 1 , 2 ) = 6
MATRIX ( 3 , 1 , 3 ) = 7
MATRIX ( 3 , 2 , 1 ) = 6
MATRIX ( 3 , 2 , 2 ) = 7
MATRIX ( 3 , 2 , 3 ) = 8
MATRIX ( 3 , 3 , 1 ) = 7
MATRIX ( 3 , 3 , 2 ) = 8
MATRIX ( 3 , 3 , 3 ) = 9

Error: Unclassifiable statement at (1) fortran

How could I fix the Unclassifiable statement error in the if () to go? The error is in
DO J=1,N
IF ( I .EQ. J )GO TO 3
Y=Y-A( I , J )*X( J )
3 END DO
program gausssiedel
INTEGER, PARAMETER :: M=100
INTEGER :: NMI, IJK , ITER, I , J
real , dimension (M,M) :: A
REAL,DIMENSION(M) :: B,X
WRITE(6 , * ) 'ECUACIONES DE ENTRADA. '
OPEN(2 ,FILE= 'datos . dat ' ,STATUS='OLD' )
READ(2 , * )N,NMI,NAPROX ! LEE DATOS DEL ARCHIVO DE ENTRADA
APROX=10.0**(-NAPROX)
DO I =1,N
READ( 2 , * ) (A( I , J ) , J=1,N) ,B( I )
WRITE( 6 , * ) (A( I , J ) , J=1,N) ,B( I )
END DO
CLOSE (2)
DO I =1,N
X( I ) = 0.0 ! PRIMERA APROXIMACION DE LA SOLUCION
END DO
WRITE(6 , * ) 'RESULTADOS'
WRITE( * , * ) ! IMPRIME RESULTADOS
DO ITER=1,NMI
WRITE( * , * )ITER , (X( J ) , J=1,N)
IJK = 0
DO I =1,N
Y=B( I )
DO J=1,N
IF ( I .EQ. J )GO TO 3
Y=Y-A( I , J )*X( J )
3 END DO
Y=Y/A( I , I )
IF (ABS( (X( I)-Y)/Y ) .GT.APROX) IJK=1
X( I ) = Y
END DO
IF ( IJK .EQ.0 )GO TO 6
END DO
WRITE( * , * ) 'NUMERO DE ITERACIONES: ' ,NMI
6 CONTINUE
pause
end program
What do you expect the do-loop to do? Are you just trying to skip the i == j value or exit the do-loop. You can achieve both without labeling the end do statement.
Skip the i == j case:
DO J=1,N
IF ( I .EQ. J ) cycle
Y=Y-A( I , J )*X( J )
END DO
Exit the loop case:
DO J=1,N
IF ( I .EQ. J ) exit
Y=Y-A( I , J )*X( J )
END DO

OpenGL is using the last texture loaded

Edit:
Ive narrowed it down to this: It seems like if I do the below in my function, and then in the renderer function never call glBindTexture again it will still render... the textures...
NM->data = stbi_load ( FileBuf , &NM->width , &NM->height , &NM->bit , 0 );
//glGenTextures ( 1 , &NM->texture [ 0 ] ); // ** OFF **
//glBindTexture ( GL_TEXTURE_2D, NM->texture [ 0 ] ); // ** OFF **
//glTexParameteri ( GL_TEXTURE_2D , GL_TEXTURE_MAG_FILTER , GL_LINEAR ); // ** Enableing This Will Render White (no texture)
glTexParameteri ( GL_TEXTURE_2D , GL_TEXTURE_MIN_FILTER , GL_LINEAR ); // ** Enableing This Will Render the texture for both objects *** SUPER WEIRD ***
// *** ALSO *** I dont ever call glBindTexture Again after this but still the object is being textured ***
glTexImage2D ( GL_TEXTURE_2D , 0 , GL_RGBA , NM->width , NM->width , 0 , GL_RGBA , GL_UNSIGNED_BYTE , NM->data );
stbi_image_free ( NM->data );
I must not be understanding something, or I have a big error in my code.
I am just trying to get WaveFront objects with materials loaded, and rendered. With that said, Im just trying to piece together some code to get a better understanding of how everything works so I can go back and reprogram everything. (I am on windows)
I can load .objects from files and even load textures... Problem is, the last texture loaded is used for all objects....
here it glIntercept for loading the images...
glGenTextures(1,05331C10)
glBindTexture(GL_TEXTURE_2D,1)
glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MAG_FILTER,GL_NEAREST)
glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MIN_FILTER,GL_NEAREST)
glTexImage2D(GL_TEXTURE_2D,0,GL_RGBA,1024,1024,0,GL_RGBA,GL_UNSIGNED_BYTE,05733040)
glGenTextures(1,05332780)
glBindTexture(GL_TEXTURE_2D,2)
glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MAG_FILTER,GL_NEAREST)
glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MIN_FILTER,GL_NEAREST)
glTexImage2D(GL_TEXTURE_2D,0,GL_RGBA,1024,1024,0,GL_RGBA,GL_UNSIGNED_BYTE,0573D040)
.. From:
NM->MapUsed = true;
sscanf ( coord [ i ]->c_str() , "map_Kd %s" , NM->map_Kd );
char FileBuf [ 256 ] = { 0x0 };
sprintf ( FileBuf , "C:\\OpenGL\\Debug\\%s" , NM->map_Kd );
NM->data = stbi_load ( FileBuf , &NM->width , &NM->height , &NM->bit , 0 );
glGenTextures ( 1 , &NM->texture );
glBindTexture ( GL_TEXTURE_2D, NM->texture );
glTexParameteri ( GL_TEXTURE_2D , GL_TEXTURE_MAG_FILTER , GL_NEAREST );
glTexParameteri ( GL_TEXTURE_2D , GL_TEXTURE_MIN_FILTER , GL_NEAREST );
glTexImage2D ( GL_TEXTURE_2D , 0 , GL_RGBA , NM->width , NM->height , 0 , GL_RGBA , GL_UNSIGNED_BYTE , NM->data );
stbi_image_free ( NM->data );
The above code is how I am loading the texture. NM is in a vector array in VectorMaterialLibrary, and that is in ObjectLoader vector...
void Renderer() {
updatecam();
// all My Objects
for ( int i = 0 ; i < ObjectLoader.size() ; i++ ) {
sObjectLoader *TempObject = ObjectLoader [ i ];
if ( TempObject->MTLFile ) {
for ( int z = 0 ; z < TempObject->VectorMaterialLibrary.size() ; z++ ) {
sMaterialLibrary *TempMaterial = TempObject->VectorMaterialLibrary [ z ];
if ( strcmp ( TempMaterial->newmtl , TempObject->usemtl ) == 0 ) {
if ( TempMaterial->MapUsed ) {
glBindTexture ( GL_TEXTURE_2D, TempMaterial->texture ); // *** This Dings 1/2 respectively ***
}
break;
}
}
}
for ( int z = 0 ; z < TempObject->_3f.size() ; z++ ) {
s3f *Temp3f = TempObject->_3f [ z ];
if ( Temp3f->GL_TYPE == GL_QUADS ) {
glBegin ( GL_QUADS );
if ( Temp3f->boolvn ) {
glNormal3f ( Temp3f->vn [ 0 ] , Temp3f->vn [ 1 ] , Temp3f->vn [ 2 ] );
}
if ( Temp3f->boolv ) {
if ( Temp3f->boolvt ) glTexCoord2f ( Temp3f->vt [ 0 ] , Temp3f->vt [ 1 ] );
glVertex3f ( Temp3f->v [ 0 ] , Temp3f->v [ 1 ] , Temp3f->v [ 2 ] );
if ( Temp3f->boolvt ) glTexCoord2f ( Temp3f->vt [ 2 ] , Temp3f->vt [ 3 ] );
glVertex3f ( Temp3f->v [ 3 ] , Temp3f->v [ 4 ] , Temp3f->v [ 5 ] );
if ( Temp3f->boolvt ) glTexCoord2f ( Temp3f->vt [ 4 ] , Temp3f->vt [ 5 ] );
glVertex3f ( Temp3f->v [ 6 ] , Temp3f->v [ 7 ] , Temp3f->v [ 8 ] );
if ( Temp3f->boolvt ) glTexCoord2f ( Temp3f->vt [ 6 ] , Temp3f->vt [ 7 ] );
glVertex3f ( Temp3f->v [ 9 ] , Temp3f->v [ 10 ] , Temp3f->v [ 11 ] );
}
glEnd();
} else {
glBegin ( GL_TRIANGLES );
if ( Temp3f->boolvn ) {
glNormal3f ( Temp3f->vn [ 0 ] , Temp3f->vn [ 1 ] , Temp3f->vn [ 2 ] );
}
if ( Temp3f->boolv ) {
if ( Temp3f->boolvt ) glTexCoord2f ( Temp3f->vt [ 0 ] , Temp3f->vt [ 1 ] );
glVertex3f ( Temp3f->v [ 0 ] , Temp3f->v [ 1 ] , Temp3f->v [ 2 ] );
if ( Temp3f->boolvt ) glTexCoord2f ( Temp3f->vt [ 2 ] , Temp3f->vt [ 3 ] );
glVertex3f ( Temp3f->v [ 3 ] , Temp3f->v [ 4 ] , Temp3f->v [ 5 ] );
if ( Temp3f->boolvt ) glTexCoord2f ( Temp3f->vt [ 4 ] , Temp3f->vt [ 5 ] );
glVertex3f ( Temp3f->v [ 6 ] , Temp3f->v [ 7 ] , Temp3f->v [ 8 ] );
}
glEnd();
}
}
}
}
Also, the glintercept for the render (took the last image1 call and the start of image2...)
glBegin(GL_TRIANGLES) Textures[ (0,1) ]
glNormal3f(0.000000,0.000000,-1.000000)
glTexCoord2f(1.000000,0.000000)
glVertex3f(1.892851,-0.950534,-3.331728)
glTexCoord2f(1.000000,1.000000)
glVertex3f(-0.107149,-0.950534,-3.331728)
glTexCoord2f(0.000000,1.000000)
glVertex3f(-0.107149,1.049466,-3.331728)
glEnd()
glBindTexture(GL_TEXTURE_2D,2)
glBegin(GL_TRIANGLES) Textures[ (0,2) ]
glNormal3f(0.000000,-1.000000,-0.000000)
glTexCoord2f(0.000000,0.000000)
glVertex3f(1.892851,-0.950534,-3.331728)
glTexCoord2f(1.000000,0.000000)
glVertex3f(1.892851,-0.950534,-1.331729)
glTexCoord2f(0.000000,1.000000)
glVertex3f(-0.107149,-0.950534,-3.331728)
glEnd()
Im wondering where I went wrong. I really just want this to work so I can recode the framework from scratch again.
If you need further code, I can post it, but I dont want a big wall!!!
// Edit, manually doing the following.. bad
// I only have 2 objects with this test, and 2 materials...
if ( testing ) {
glGenTextures ( 2 , Gtextures ); // ********Global
testing = false;
NM->data = stbi_load ( FileBuf , &NM->width , &NM->height , &NM->bit , 0 );
glBindTexture ( GL_TEXTURE_2D, Gtextures[0] );
glTexParameteri ( GL_TEXTURE_2D , GL_TEXTURE_MAG_FILTER , GL_NEAREST );
glTexParameteri ( GL_TEXTURE_2D , GL_TEXTURE_MIN_FILTER , GL_NEAREST );
glTexImage2D ( GL_TEXTURE_2D , 0 , GL_RGBA , NM->width , NM->height , 0 , GL_RGBA , GL_UNSIGNED_BYTE , NM->data );
stbi_image_free ( NM->data );
} else {
NM->data = stbi_load ( FileBuf , &NM->width , &NM->height , &NM->bit , 0 );
glBindTexture ( GL_TEXTURE_2D, Gtextures[1] );
glTexParameteri ( GL_TEXTURE_2D , GL_TEXTURE_MAG_FILTER , GL_NEAREST );
glTexParameteri ( GL_TEXTURE_2D , GL_TEXTURE_MIN_FILTER , GL_NEAREST );
glTexImage2D ( GL_TEXTURE_2D , 0 , GL_RGBA , NM->width , NM->height , 0 , GL_RGBA , GL_UNSIGNED_BYTE , NM->data );
stbi_image_free ( NM->data );
}
**
for ( int z = 0 ; z < TempObject->VectorMaterialLibrary.size() ; z++ ) {
sMaterialLibrary *TempMaterial = TempObject->VectorMaterialLibrary [ z ];
if ( strcmp ( TempMaterial->newmtl , TempObject->usemtl ) == 0 ) {
if ( TempMaterial->MapUsed ) {
//mbci ( "Changing Texture" , i );
//mbci ( "Gtextures [ i ]" , Gtextures [ i ] );
glBindTexture ( GL_TEXTURE_2D, Gtextures [ i ] ); // ** I only have 2 objects so this works for loading the 2 textures...
//glBindTexture ( GL_TEXTURE_2D, TempMaterial->texture );
}
break;
}
}
But the object is STILL the same texture...
Here is a picture of something I am rendering. Notice everything is the same color... The two cubes in the middle should be two different colors, and the other objects are also taking the same texture... here are the two textures (scaled down ofc)
What I See http://i.stack.imgur.com/s1NXn.png ** No Idea **
Cube UV1 http://i.stack.imgur.com/s44Tb.png ** This is loaded first**
Cube UV2 http://i.stack.imgur.com/8KXdo.png ** This is loaded last **
I hate to do this, but after a couple days debugging and going over my OpenGL booklets I have answered my own question.
The problem with my code was based on the .obj format and how I am ordering the faces. In .obj format each .obj is incremented... example:
OBJECT ONE
f 5/1/1 6/2/1 1/3/1
f 6/1/2 7/2/2 2/3/2
f 7/1/3 8/2/3 3/3/3
f 8/1/4 5/2/4 4/3/4
f 1/1/5 2/2/5 4/3/5
f 8/1/6 7/2/6 5/3/6
f 6/2/1 2/4/1 1/3/1
f 7/2/2 3/4/2 2/3/2
f 8/2/3 4/4/3 3/3/3
f 5/2/4 1/4/4 4/3/4
f 2/2/5 3/4/5 4/3/5
f 7/2/6 6/4/6 5/3/6
OBJECT TWO
f 9/5/7 10/6/7 12/7/7
f 13/5/8 16/6/8 14/7/8
f 9/5/9 13/6/9 10/7/9
f 10/5/10 14/6/10 11/7/10
f 11/5/11 15/6/11 12/7/11
f 13/5/12 9/6/12 16/7/12
f 10/6/7 11/8/7 12/7/7
f 16/6/8 15/8/8 14/7/8
f 13/6/13 14/8/13 10/7/13
f 14/6/10 15/8/10 11/7/10
f 15/6/11 16/8/11 12/7/11
f 9/6/12 12/8/12 16/7/12
How I was storing the Vertex/VertexTexture/VertexNormals, were correct, but my loop was starting from 0 on the second object, meaning I was actually recreating the first objects all over again, thus it applied the last texture...
To anyone else: Please be aware of how your program is storing and reading things.
A couple days of work with only a single line of code changed to make it functional... yippie.
It would be nice if there were a way to make sure blender did not do this...

conditional group by with query api

Supose a student attandance system.
For a student and a course we have N:M relation named attandance.
Also whe have a model with attandances status (present, absent, justified, ...).
level( id, name, ... )
student ( id, name, ..., id_level )
course( id, name, ... )
status ( id, name, ...) #present, absemt, justified, ...
attandance( id, id_student, id_course, id_status, date, hour )
unique_together = ((id_student, id_course, id_status, date, hour),)
I'm looking for a list of students with >20% of absent for a level sorted by %. Something like:
present = status.objects.get( name = 'present')
justified = status.objects.get( name = 'justified')
absent = status.objects.get( name = 'absent')
#here the question. How to do this:
Student.objects.filter( level = level ).annotate(
nPresent =count( attandence where status is present or justified ),
nAbsent =count( attandence where status is absent ),
pct = nAbsent / (nAbsent + nPresent ),
).filter( pct__gte = 20 ).order_by( "-pct" )
If it is not possible to make it with query api, any workaround (lists, sets, dictionaris, ...) is wellcome!
thanks!
.
.
.
---- At this time I have a dirty raw sql writed by hand --------------------------
select
a.id_alumne,
coalesce ( count( p.id_control_assistencia ), 0 ) as p,
coalesce ( count( j.id_control_assistencia ), 0 ) as j,
coalesce ( count( f.id_control_assistencia ), 0 ) as f,
1.0 * coalesce ( count( f.id_control_assistencia ), 0 ) /
( coalesce ( count( p.id_control_assistencia ), 0 ) + coalesce ( count( f.id_control_assistencia ), 0 ) ) as tpc
from
alumne a
inner join
grup g
on (g.id_grup = a.id_grup )
inner join
curs c
on (c.id_curs = g.id_curs)
inner join
nivell n
on (n.id_nivell = c.id_nivell)
inner join
control_assistencia ca
on (ca.id_estat is not null and
ca.id_alumne = a.id_alumne )
inner join
impartir i
on ( i.id_impartir = ca.id_impartir )
left outer join
control_assistencia p
on (
p.id_estat in ( select id_estat from estat_control_assistencia where codi_estat in ('P','R' ) ) and
p.id_control_assistencia = ca.id_control_assistencia )
left outer join
control_assistencia j
on (
j.id_estat = ( select id_estat from estat_control_assistencia where codi_estat = 'J' ) and
j.id_control_assistencia = ca.id_control_assistencia )
left outer join
control_assistencia f
on (
f.id_estat = ( select id_estat from estat_control_assistencia where codi_estat = 'F' ) and
f.id_control_assistencia = ca.id_control_assistencia )
where
n.id_nivell = {0} and
i.dia_impartir >= '{1}' and
i.dia_impartir <= '{2}'
group by
a.id_alumne
having
1.0 * coalesce ( count( f.id_control_assistencia ), 0 ) /
( coalesce ( count( p.id_control_assistencia ), 0 ) + coalesce ( count( f.id_control_assistencia ), 0 ) )
> ( 1.0 * {3} / 100)
order by
1.0 * coalesce ( count( f.id_control_assistencia ), 0 ) /
( coalesce ( count( p.id_control_assistencia ), 0 ) + coalesce ( count( f.id_control_assistencia ), 0 ) )
desc
'''.format( nivell.pk, data_inici, data_fi, tpc )
If you don't care too much whether it uses the query api or python after the fact, use itertools.groupby.
attendances = Attendance.objects.select_related().filter(student__level__exact=level)
students = []
for s, g in groupby(attendances, key=lambda a: a.student.id):
g = list(g) # g is an iterator
present = len([a for a in g if a.status == 'present'])
absent = len([a for a in g if a.status == 'absent'])
justified = len([a for a in g if a.status == 'justified'])
total = len(g)
percent = int(absent / total)
students.append(dict(name=s.name, present=present, absent=absent, percent=percent))
students = (s for s in sorted(students, key=lambda x: x['percent']) if s['percent'] > 25)
You can pass the resulting list of dicts to the view the same way you would any other queryset.