int main(int argc, char *argv[]) { int i, j, k; double Ti, Mj, percent; vector *T, *M; matrix *t, *Jij, *betaij, *output, *ttmp; /* if(argc < 3) { printf("Usage:\n" "fitcreep: <file> <t1> <t2> ... <tn>\n" "<file>: Filename containing the creep function data.\n" "<t1>: First retardation time\n" "<t2>: Second retardation time\n" "...\n" "<tn>: Nth retardation time.\n"); exit(0); } */ T = linspaceV(333, 363, 10); M = linspaceV(.05, .4, 10); ttmp = linspace(1e-3, 1e3, 1000); t = mtxtrn(ttmp); DestroyMatrix(ttmp); output = CreateMatrix(len(T)*len(M), 2+5); for(i=0; i<len(T); i++) { Ti = valV(T, i); for(j=0; j<len(M); j++) { Mj = valV(M, j); Jij = makedata(t, Ti, Mj); betaij = fitdata(t, Jij); setval(output, Ti, i*len(M)+j, 0); setval(output, Mj, i*len(M)+j, 1); setval(output, val(Jij, 0, 0), i*len(M)+j, 2); for(k=0; k<nRows(betaij); k++) setval(output, pow(val(betaij, k, 0), 2), i*len(T)+j, k+3); DestroyMatrix(Jij); DestroyMatrix(betaij); /* Print the percent done */ percent = (1.*i*len(M)+j)/(len(M)*len(T))*100.; printf("%3.2f %%\r", percent); fflush(stdout); } } DestroyMatrix(t); DestroyVector(T); DestroyVector(M); mtxprntfilehdr(output, "output.csv", "T,M,J0,J1,tau1,J2,tau2\n"); DestroyMatrix(output); return 0; }
static int populate_shaders(Vector *shaders) { size_t i; size_t n; hash *shader; set *S; char *name, *vshader, *fshader; if (!shaders) return -1; n = sizeVector(shaders); for(i = 0; i < n; i++) { S = CreateSet(); shader = (hash *) atVector(shaders, i); name = (char *) FindHashElement(shader, "name"); vshader = (char *) FindHashElement(shader, "vshader"); fshader = (char *) FindHashElement(shader, "fshader"); if (!name) return i; if (!vshader) return i; if (!fshader) return i; InsertSetElement(S, "name"); InsertSetElement(S, "vshader"); InsertSetElement(S, "fshader"); RegisterShaderScene(name, vshader, fshader); // clean free(name); free(vshader); free(fshader); check_and_destroy("populate_shaders", shader, S); } DestroyVector(&shaders); return -1; }
static int populate_gobjs(Vector *gObjects) { size_t i; size_t n; hash *gobj_hash; set *S; char *fname, *dirname; if (!gObjects) return -1; n = sizeVector(gObjects); for(i = 0; i < n; i++) { S = CreateSet(); gobj_hash = (hash *) atVector(gObjects, i); fname = (char *) FindHashElement(gobj_hash, "fname"); dirname= (char *) FindHashElement(gobj_hash, "dirname"); if (!fname) return i; if (!dirname) return i; InsertSetElement(S, "fname"); InsertSetElement(S, "dirname"); SceneRegisterGObject(dirname, fname); // clean free(fname); free(dirname); check_and_destroy("populate_gobjs", gobj_hash, S); } // clean DestroyVector(&gObjects); return -1; }
static void wipe_vector(Vector *v) { size_t i, n; char *str; n = sizeVector(v); for(i = 0; i < n; ++i) { str = atVector(v, i); free(str); } DestroyVector(&v); }
static trfm3D *parse_trfms(Vector *trfms) { size_t i; size_t n = sizeVector(trfms); hash *trfm; trfm3D *T; T = CreateTrfm3D(); for(i = 0; i < n; ++i) { trfm = (hash *) atVector(trfms, i); apply_trfm(trfm, T); } DestroyVector(&trfms); return T; }
void TSRModelInstance::BindAnimations( TSRModel* pAnimationsModel ) { DestroyVector( m_AnimationNodes ); m_AnimationNodes.clear(); m_AnimationNodes.reserve( pAnimationsModel->m_AnimationsCount ); int testRandStart = 0;//rand() % 25; for ( unsigned int i = 0; i < pAnimationsModel->m_AnimationsCount; i++ ) { TSRModelAnimation& CurrAnimation = pAnimationsModel->m_pAnimations[ i ]; TSRModelNodeAnimation* pNewNodeAnimation = new TSRModelNodeAnimation(); pNewNodeAnimation->m_InputIndex = testRandStart; pNewNodeAnimation->m_InputValue = CurrAnimation.m_pInputs[ pNewNodeAnimation->m_InputIndex ]; pNewNodeAnimation->m_pAnimation = &CurrAnimation; pNewNodeAnimation->m_pNode = FindNode( CurrAnimation.m_TargetNodeName ); pNewNodeAnimation->m_Transform.MakeIdent(); m_AnimationNodes.push_back( pNewNodeAnimation ); CurrAnimation.m_pNode = FindNode( CurrAnimation.m_TargetNodeName ); m_NodesToAnimationsMap[ CurrAnimation.m_pNode ] = pNewNodeAnimation; } }
/** * @brief Used to destroy an instance of the Matrix3d struct * @param toDestroy The instance to free */ void DestroyMatrix(Matrix3d* toDestroy) { DestroyVector(toDestroy->_firstRow); DestroyVector(toDestroy->_secondRow); DestroyVector(toDestroy->_thirdRow); free(toDestroy); }
// refresh the items void TSRGuiFileBrowser::Refresh() { int numItems = ( int )( m_FilesNames.size() + m_FoldersNames.size() ); // all children will be re added m_Children.clear(); // those must be deallocated DestroyVector( m_FileItems ); DestroyVector( m_DirectoryItems ); float fTextSize = TSRText::GetSize(); // create the scroll bars and the label m_VScrollBar.m_bTransparent = m_bTransparent; m_VScrollBar.m_BorderColor = m_BorderColor; m_VScrollBar.m_BarType = SCROLLBAR_TYPE_VERTICAL; m_VScrollBar.SetSize( fTextSize, m_Size.y - fTextSize * 2 ); m_VScrollBar.SetPosition( m_Size.x - fTextSize, fTextSize ); m_HScrollBar.m_bTransparent = m_bTransparent; m_HScrollBar.m_BorderColor = m_BorderColor; m_HScrollBar.m_BarType = SCROLLBAR_TYPE_HORIZONTAL; m_HScrollBar.SetSize( m_Size.x - fTextSize, fTextSize ); m_HScrollBar.SetPosition( 0.0f, 0.0f ); m_Label.m_bTransparent = m_bTransparent; m_Label.m_bBordered = m_bBordered; m_Label.m_BorderColor = m_BorderColor; m_Label.m_Text = m_Path; m_Label.m_TextColor.Assign( 1.0f, 0.0f, 0.0f ); m_Label.SetPosition( 0.0f, m_Size.y - fTextSize ); m_Label.SetTextAlign( GUI_ALIGN_TOPLEFT ); m_Label.SetSize( m_Size.x, fTextSize ); // put the label and the scroll bar as children AddChild( m_VScrollBar ); AddChild( m_HScrollBar ); AddChild( m_Label ); // this will be decremented after adding each item float currentY = m_Size.y - fTextSize * 2.0f; // fix the scroll bar index // which will tell us from where to start m_VScrollBar.m_MaxItems = m_usCharHeight + 1; m_VScrollBar.m_NumItems = numItems + 4; m_VScrollBar.FixIndex(); // fix the horizontal bar index m_HScrollBar.m_MaxItems = m_usCharWidth - 1; m_HScrollBar.m_NumItems = m_Maxcharacters; m_HScrollBar.FixIndex(); int charIndex = m_HScrollBar.m_StartIndex; int startIndex = m_VScrollBar.m_StartIndex; int currIndex = 0; // create directory items for ( unsigned int i = 0; i < m_FoldersNames.size(); i++ ) { if ( currIndex >= startIndex ) { if ( m_VScrollBar.m_MaxItems == m_Children.size() ) { break; } // create a new directory item as a static text TSRGuiStaticText* pNewChild = new TSRGuiStaticText(); pNewChild->SetSize( m_Size.x - fTextSize, fTextSize ); char* pFolderName = ( char* ) m_FoldersNames[ i ].c_str(); if ( charIndex <= ( int ) strlen( pFolderName ) ) { pNewChild->SetText( &pFolderName[ charIndex ] ); } else { pNewChild->SetText( "" ); } pNewChild->SetPosition( 0.0f, currentY ); pNewChild->m_bTransparent = true; pNewChild->m_bBordered = false; pNewChild->m_TextColor = m_FolderColor; pNewChild->m_bClickable = true; pNewChild->SetTextAlign( GUI_ALIGN_TOPLEFT ); pNewChild->m_ActiveColor.Assign( 1.0f, 1.0f, 0.0f ); pNewChild->m_usCharWidth = m_usCharWidth - 1; AddChild( *pNewChild ); m_DirectoryItems.push_back( pNewChild ); currentY -= fTextSize; } currIndex++; } // create file items for ( unsigned int i = 0; i < m_FilesNames.size(); i++ ) { if ( currIndex >= startIndex ) { if ( m_VScrollBar.m_MaxItems == m_Children.size() ) { break; } char* pFileName = (char*) m_FilesNames[ i ].c_str(); // create a new file item as a static text TSRGuiStaticText* pNewChild = new TSRGuiStaticText(); pNewChild->SetSize( m_Size.x - fTextSize, fTextSize ); if ( charIndex <= ( int ) strlen( pFileName ) ) { pNewChild->SetText( &pFileName[ charIndex ] ); } else { pNewChild->SetText( "" ); } pNewChild->SetPosition( 0.0f, currentY ); pNewChild->m_bTransparent = true; pNewChild->m_bBordered = false; pNewChild->m_TextColor = m_FileColor; pNewChild->m_bClickable = true; pNewChild->SetTextAlign( GUI_ALIGN_TOPLEFT ); pNewChild->m_ActiveColor.Assign( 1.0f, 1.0f, 0.0f ); AddChild( *pNewChild ); m_FileItems.push_back( pNewChild ); currentY -= fTextSize; } currIndex++; } }
static Node *populate_nodes(hash *nodeH) { Vector *v; trfm3D *T; size_t i, n; char *name, *str; int has_gobj = 0; GObject *gobj; set *S; Node *myNode; S = CreateSet(); name = FindHashElement(nodeH, "name"); if (name) InsertSetElement(S, "name"); myNode = CreateNode(); v = FindHashElement(nodeH, "trfm"); if (v) { InsertSetElement(S, "trfm"); T = parse_trfms(v); SetTrfmNode(myNode, T); } str = FindHashElement(nodeH, "shader"); if (str) { InsertSetElement(S, "shader"); SetShaderNode(myNode, FindShaderScene(str)); free(str); } str = FindHashElement(nodeH, "gObj"); if (str) { InsertSetElement(S, "gObj"); has_gobj = 1; gobj = SceneFindNameGObject(str); if(!gobj) { fprintf(stderr, "[E] populate_node: %s not found\n", str); PrintRegisteredGobjs(); exit(1); } SetGobjNode(myNode, gobj); free(str); } v = (Vector *) FindHashElement(nodeH, "childs"); if (v) { InsertSetElement(S, "childs"); if (has_gobj) { fprintf(stderr, "[E] populate_nodes: node %s has gObj and children\n", name); exit(1); } n = sizeVector(v); for(i = 0; i < n; ++i) { AttachNode(myNode, populate_nodes((hash *) atVector(v, i))); } DestroyVector(&v); } DestroyTrfm3D(&T); check_and_destroy("populate_nodes", nodeH, S); return myNode; }
static int populate_lights(Vector *lights) { size_t i; size_t n; int s; hash *light_h; char *name, *type, *aux; Vector *v; set *S; float r, g, b, w; float rgb[3], pos4[4]; float cutoff = 30.0; float exp = 10.0; Light *l; if (!lights) return -1; n = sizeVector(lights); for(i = 0; i < n; i++) { S = CreateSet(); light_h = (hash *) atVector(lights, i); name = (char *) FindHashElement(light_h, "name"); type = (char *) FindHashElement(light_h, "type"); if (!check_light_type(type)) { fprintf(stderr, "[E] populate_lights: bad light type %s (possible values \"positional\", \"directional\", \"spotlight\")\n", type); exit(1); } if (!name) return i; if (!type) return i; InsertSetElement(S, "name"); InsertSetElement(S, "type"); l = SceneRegisterLight(name); v = (Vector *) FindHashElement(light_h, "pos"); if (v) { InsertSetElement(S, "pos"); read_xyz(v, &pos4[0], &pos4[1], &pos4[2]); pos4[3] = 1.0; if (!strcmp(type, "directional")) pos4[3] = 0.0; SetPositionLight(l, &pos4[0]); } v = (Vector *) FindHashElement(light_h, "amb"); if (v) { InsertSetElement(S, "amb"); read_xyz(v, &rgb[0], &rgb[1], &rgb[2]); SetAmbientLight(l, &rgb[0]); } v = (Vector *) FindHashElement(light_h, "dif"); if (v) { InsertSetElement(S, "dif"); read_xyz(v, &rgb[0], &rgb[1], &rgb[2]); SetDiffuseLight(l, &rgb[0]); } v = (Vector *) FindHashElement(light_h, "spec"); if (v) { InsertSetElement(S, "spec"); read_xyz(v, &rgb[0], &rgb[1], &rgb[2]); SetSpecularLight(l, &rgb[0]); } if (!strcmp(type, "spotlight")) { aux = (char *) FindHashElement(light_h, "exp"); if (aux) { InsertSetElement(S, "exp"); sscanf(aux, "%f", &exp); if (exp < 0) { fprintf(stderr, "[E] populate_lights: negative exponent\n"); exit(1); } free(aux); } aux = (char *) FindHashElement(light_h, "cutoff"); if (aux) { InsertSetElement(S, "cutoff"); sscanf(aux, "%f", &cutoff); if (exp < 0) { fprintf(stderr, "[E] populate_lights: negative cutoff\n"); exit(1); } free(aux); } rgb[0] = 0.577; rgb[1] = 0.577; rgb[2] = 0.577; v = (Vector *) FindHashElement(light_h, "spdir"); if (v) { InsertSetElement(S, "spdir"); read_xyz(v, &rgb[0], &rgb[1], &rgb[2]); } SetSpotLight(l, &rgb[0], cutoff, exp); } aux = (char *) FindHashElement(light_h, "switched"); if (aux) { InsertSetElement(S, "switched"); sscanf(aux, "%d", &s); if (!s) SwitchLight(l, 0); free(aux); } free(type); free(name); check_and_destroy("populate_lights", light_h, S); //DestroyHash(&light_h); } DestroyVector(&lights); return -1; }