/** * initialize general properties */ void alignInit() { //vector mid; listNode *ln; /* apply the moving actions if this isn't the first image */ if(curSlice > 0) { /* find the initial placement of the ref image */ refImgBounds.v1.x = 0; refImgBounds.v1.y = 0; refImgBounds.v2.x = ref->width; refImgBounds.v2.y = 0; refImgBounds.v3.x = ref->width; refImgBounds.v3.y = ref->height; refImgBounds.v4.x = 0; refImgBounds.v4.y = ref->height; /* get the action list to apply/modify, create if it doesn't exist */ while(NULL == (ln=getListNode(curDataset->sliceActionLists,curSlice-1))) { actions = newList(LIST); enqueue(curDataset->sliceActionLists, actions); } actions = (list*) ln->data; /* apply the actions */ refImgBounds = applyActions(actions,refImgBounds); } /* find the initial placement of the moving image */ movImgBounds.v1.x = 0; movImgBounds.v1.y = 0; movImgBounds.v2.x = mov->width; movImgBounds.v2.y = 0; movImgBounds.v3.x = mov->width; movImgBounds.v3.y = mov->height; movImgBounds.v4.x = 0; movImgBounds.v4.y = mov->height; curDataset->width = mov->width; curDataset->height = mov->height; curRotCenter.x = (movImgBounds.v1.x+movImgBounds.v3.x)/2.0; curRotCenter.y = (movImgBounds.v1.y+movImgBounds.v3.y)/2.0; /* get the moving action list to apply/modify, create if it doesn't exist */ while(NULL == (ln = getListNode(curDataset->sliceActionLists,curSlice))) { actions = newList(LIST); enqueue(curDataset->sliceActionLists, actions); } actions = (list*) ln->data; /* apply the actions */ movImgBounds = applyActions(actions,movImgBounds); /* turn on animation */ animate = TRUE; strcpy(alertString,""); alignTimerEvent(0); }
void initNode() { int i = 0, j = 0; g_listIndexFlag = 0; for (i = 0; i < g_listSize; ++i) { g_ListNode[i].index = i; g_listIndex[g_listIndexFlag++] = i; } for (i = 0; i < 81; ++i) { CellNode& node = g_allNode[i]; node.index = i; node.optionNum = 9; for (j = 0; j < 10; ++j) { node.options[j] = 0; } node.affecteList = getListNode(); ListNode* head = node.affecteList; head->next = 0; for (j = 0; j < g_relative_index_size; ++j) { ListNode* nd = getListNode(); nd->next = 0; nd->value = g_relative_index[i][j]; head->next = nd; head = nd; } } }
/** * delete a list of slice contours */ void deleteSliceContours(list *slices) { listNode *i,*j; int k,l; list *slice; contour *cont; for(i = getListNode(slices,0), k = 0; i; k++, i = (listNode*) i->next) { slice = (list*) i->data; for(j = getListNode(slice,0), l = 0; j; l++, j = (listNode*) j->next) { cont = (contour*) j->data; deleteContour(cont); } freeList(slice); } freeList(slices); }
void *operate(void *arg) { pthread_mutex_t insMutex = PTHREAD_MUTEX_INITIALIZER; pthread_mutex_lock(&insMutex); struct num *NS = (struct num*)arg; int *N; N = NS->nums; int size = NS->len; struct list *lst = getListNode(); for(int i=0;i<size;++i){ int no = *(N+i); insert(lst,no); } printf("\nlist\n"); traverse(lst); pthread_mutex_unlock(&insMutex); }
void XMLNodeList::replaceAtIndex(int index, const XMLElement & elem) { xmlNode *n = getListNode(index); if (n && n != elem.getRealNode()) { if (index == 1) { scope->unregisterNodeListPointer(parent->children); } xmlNode *previous = n->prev; xmlNode *next = n->next; xmlNode *cpy = xmlCopyNode(elem.getRealNode(), 1); xmlUnlinkNode(cpy); xmlReplaceNode(n, cpy); xmlFreeNode(n); prevNode = cpy; cpy->prev = previous; cpy->next = next; if (index == 1) { scope->registerPointers(parent->children, this); } } }
void list_merge_at(List headList ,int index ,List tailList){ if(tailList==NULL||headList==NULL) return; ListNode head=headList->nodes; ListNode n=tailList->nodes; ListNode nLast=getLastListNode(n); if (index==-1){ nLast->next=head; headList->size+=tailList->size; headList->nodes=n; return ; } ListNode indexListNode = getListNode(head,index); if (indexListNode==NULL){ //为NULL 有两种情况,一种是head==NULL, 另一种是index 越界, if (head==NULL){//如果head 是NULL, 则返回n ,相当于head 原本的长度为0, headList->size=tailList->size; headList->nodes=n; return ; }else{//另一种是index 越界, 则直接将n添加到head 末尾 ListNode headLastNode=getLastListNode(head); headList->size+=tailList->size; headLastNode->next=n; return ; } } ListNode nextListNode=indexListNode->next; indexListNode->next=n; nLast->next=nextListNode; headList->size+=tailList->size; return; }
/** * apply a set of actions to an image coordinate */ quadri applyActions(list *l, quadri base) { listNode *i; action *a; quadri res = base; /* apply each action in turn, add them to the current list */ for(i = getListNode(l,0); i; i = (listNode*) i->next) { /* get the action */ a = (action*) i->data; /* apply action and add it to the list */ switch(a->type) { case TRANSLATION: res = getQuadTranslation(res, a->trans); break; case ROTATION: res = getQuadRotation(res, a->rotCenter, a->angle); break; case SCALE: res = getQuadScale(res, a->scale); break; default: fprintf(stderr, "error: unrecognized action type %d\n", a->type); } } return res; }
void list_delete_at(List list ,int index){ ListNode head=list->nodes; if(index<0||list==NULL||list->size==0){ return ; } if(index==0){ ListNode next=head->next; head->next=NULL; free(head->ele); free(head); list->nodes=next; list->size--; return ; } ListNode pro= getListNode(head,index-1); if(pro==NULL){//如果index 越界,则不删除任何元素 return ; } ListNode n= pro->next; if (n!=NULL){ pro->next=n->next; n->next=NULL; free(n->ele); free(n); list->size--; } }
ListNode *getListNode(int* nums, int n) { vector<int> vecNums; for (int i = 0; i < n; i++) vecNums.push_back(nums[i]); return getListNode(vecNums); }
void XMLNodeList::insertAtIndex(int index, const XMLElement & elem) { xmlNode *n = getListNode(index); if (n) { xmlNode *cpy = xmlCopyNode(elem.getRealNode(), 1); xmlUnlinkNode(cpy); xmlAddNextSibling(n, cpy); size++; } }
/** * read a set of slice contour labels from a file */ int readSliceContourLabels(list *slices, char *filename) { listNode *sliceNode, *contNode, *vertNode; contour *cont; vertex *v; int i; /* open the file */ FILE *fp = fopen(filename,"r"); /* validate */ if(fp == NULL) { fprintf(stderr,"error: surfIO.c couldn't open the slice contour file %s for reading\n", filename); return SR_FAILURE; } //fprintf(fp,"# slice contour file created by libsr\n# %s\n\n", SURF_IO_VERSION_C); /* read each label */ for(sliceNode = getListNode(slices,0), i = 0; !feof(fp) && sliceNode; sliceNode = (listNode*) sliceNode->next, i++) { /* iterate over the contours in this slice */ for(contNode = getListNode((list*) sliceNode->data,0); !feof(fp) && contNode; contNode = (listNode*) contNode->next) { cont = (contour*) contNode->data; /* iterate over the vertices, writing each label */ for(vertNode = getListNode(cont->vertices,0); !feof(fp) && vertNode; vertNode = (listNode*) vertNode->next) { v = (vertex*) vertNode->data; fscanf(fp,"%d\n", &v->label); } } } fclose(fp); return SR_SUCCESS; }
void list_modify_at (List list ,Void ele ,int index ){ ListNode listNode=list->nodes; if (listNode==NULL||index<0){ return ; } ListNode indexNode=getListNode(listNode,index); if (indexNode!=NULL){ free(indexNode->ele); indexNode->ele=ele; return ; } return ; }
ListNode mergeListNodeAt(ListNode head ,int index ,ListNode tail){ if (head==NULL) return tail ; ListNode nLast=getLastListNode(tail); if (index==-1){ nLast->next=head; return tail; } ListNode indexListNode = getListNode(head,index); if (indexListNode==NULL){ //index 越界, ListNode headLastNode=getLastListNode(head); headLastNode->next=tail; return head; } ListNode nextListNode=indexListNode->next; indexListNode->next=tail; nLast->next=nextListNode; return head; }
const XMLObject *XMLNodeList::getListElement(int index) { xmlNode *n = getListNode(index); if (n) { XMLObject *obj = scope->getXMLObjectFromLibXMLPtr(n); if (obj) { return static_cast < XMLElement * >(obj); } return new XMLElement(doc, n); } return 0; }
/** * adds a specified number of pixels to the image in each direction, * adds action to the list * propagates the change through the align actions of all images after * this one to maintain consistency */ void applyScale(vector scaleAction) { listNode *i,*j,*k; list *postActions, *postContour, *postTackList; vertex *curTack; /* try to add the action to the list */ if(!addScaleAction(actions,scaleAction)) { fprintf(stderr, "error: can't allocate memory to store a scale action\n"); } else { /* consolodate the action list */ consolidateActions(actions); /* apply the rotation to the moving image */ movImgBounds = getQuadScale(movImgBounds, scaleAction); /* apply the scale to all future action lists */ for(i = getListNode(curDataset->sliceActionLists,curSlice+1); i; i = (listNode*) i->next) { postActions = (list*) i->data; if(!addScaleAction(postActions, scaleAction)) { fprintf(stderr, "error: can't allocate memory to store a scale action\n"); } else { /* successful allocation, consolodate */ consolidateActions(postActions); } } /* apply the scale to all tacks on & after this slice */ for(i = getListNode(curDataset->sliceContourLists,curSlice); i; i = (listNode*) i->next) { postContour = (list*) i->data; for(j = getListNode(postContour,0); j; j = (listNode*) j->next) { postTackList = ((contour*) j->data)->vertices; for(k = getListNode(postTackList,0); k; k = (listNode*) k->next) { curTack = (vertex*) k->data; doScaleAction(&curTack->x, &curTack->y, scaleAction); } } } /* apply the scale to all markers on & after this slice */ for(i = getListNode(curDataset->sliceMarkerLists,curSlice); i; i = (listNode*) i->next) { postContour = (list*) i->data; for(j = getListNode(postContour,0); j; j = (listNode*) j->next) { curTack = (vertex*) j->data; doScaleAction(&curTack->x, &curTack->y, scaleAction); } } } }
void unsetijNode(int index, int v) { g_buf[index] = 0; int i = 0; int r_index; CellNode& myNode = g_allNode[index]; int affecteNum = myNode.affecteNum; for (i = 0; i < affecteNum; ++i) { r_index = myNode.affectes[i][0]; CellNode& node = g_allNode[r_index]; node.optionNum = myNode.affectes[i][1]; node.options[v] = myNode.affectes[i][2]; ListNode* newNode = getListNode(); newNode->value = index; newNode->next = node.affecteList->next; node.affecteList->next = newNode; } myNode.affecteNum = 0; }
void XMLNodeList::removeElementAtPosition(int index) { if (size && index >= 1 && index <= size) { if (index == 1) { xmlNode *n = parent->children; scope->unregisterNodeListPointer(n); xmlUnlinkNode(n); xmlFreeNode(n); size--; if (size == 0) { parent->children = 0; } prevNode = parent->children; scope->registerPointers(parent->children, this); prev = 1; } else { xmlNode *n = getListNode(index); if (n) { xmlNode *next = n->next; prevNode = prevNode->prev; prev--; xmlUnlinkNode(n); xmlFreeNode(n); prevNode->next = next; size--; } } } }
/** * write a set of slice contours to a file */ int writeSliceContours(list *slices, char *filename) { listNode *sliceNode, *contNode, *vertNode, *adjNode; contour *cont; vertex *v; int i; /* open the file */ FILE *fp = fopen(filename,"w"); /* validate */ if(fp == NULL) { fprintf(stderr,"error: surfIO.c couldn't open the slice contour file %s for writing\n", filename); return SR_FAILURE; } //fprintf(fp,"# slice contour file created by libsr\n# %s\n\n", SURF_IO_VERSION_C); /* write each slice */ for(sliceNode = getListNode(slices,0), i = 0; sliceNode; sliceNode = (listNode*) sliceNode->next, i++) { if(sliceEmpty((list*) sliceNode->data)) continue; fprintf(fp,"slice %lf\n", ((vertex*) getListNode(((contour*) getListNode((list*) sliceNode->data, 0)->data)->vertices, 0)->data)->z); /* iterate over the contours in this slice */ for(contNode = getListNode((list*) sliceNode->data,0); contNode; contNode = (listNode*) contNode->next) { cont = (contour*) contNode->data; /* print the info for this contour */ fprintf(fp, "contour "); switch(cont->closed) { case OPEN: fprintf(fp,"open"); break; case CLOSED: fprintf(fp,"closed"); break; } fprintf(fp,"\n"); /* iterate over the vertices, writing each */ for(vertNode = getListNode(cont->vertices,0); vertNode; vertNode = (listNode*) vertNode->next) { v = (vertex*) vertNode->data; fprintf(fp,"%lf %lf\n", v->x, v->y); } fprintf(fp,"adjacent\n"); /* iterate over the adjacent contours, writing the indices */ for(adjNode = getListNode(cont->adjacentContours,0); i+1 < listSize(slices)&& adjNode; adjNode = (listNode*) adjNode->next) { fprintf(fp, "%d ", findInListI((list*) getListNode(slices,i+1)->data, adjNode->data)); } fprintf(fp,"-1\n"); } } fclose(fp); return SR_SUCCESS; }
/** * read a set of slice contours from a file */ list *readSliceContours(char *filename) { list *slices, *slice, *nextSlice; contour *cont; listNode *sliceNode, *contNode, *adjNode, *lnAdj; intNode *in; vertex *v; char str[10*SR_MAX_STR_LEN]; double sliceZ; int adjIndex; /* open the file */ FILE *fp = fopen(filename,"r"); /* validate */ if(fp == NULL) { fprintf(stderr,"error: surfIO.c couldn't open the slice contour file %s for reading\n", filename); return NULL; } skipComments(fp,'#'); /* create the slices */ slices = newList(LIST); /* read the first string */ fscanf(fp, "slice "); /* read the file */ while(!feof(fp)) { /* read the z coordinate */ fscanf(fp, "%lf", &sliceZ); slice = newList(LIST); enqueue(slices,slice); /* read the next string and test for new slice */ fscanf(fp, "%s ", str); while(!strcmp(str,"contour")) { /* while we are still reading contours */ cont = createContour(); enqueue(slice,cont); /* read closure state */ fscanf(fp, "%s", str); if(!strcmp(str,"closed")) { cont->closed = CLOSED; } /* read the first string on the next line, test for "adjacent" */ fscanf(fp, "%s", str); while(strcmp(str,"adjacent")) { /* create and read this vertex */ v = createVertex(); v->x = atof(str); fscanf(fp, "%lf", &v->y); v->z = sliceZ; enqueue(cont->vertices,v); fscanf(fp, "%s", str); } /* read the adjacent contours as ints, convert to pointers later */ fscanf(fp, "%d", &adjIndex); while(adjIndex != -1) { /* add this index to the list */ in = (intNode*) malloc(sizeof(intNode)); in->val = adjIndex; enqueue(cont->adjacentContours,in); fscanf(fp, "%d", &adjIndex); } fscanf(fp, "%s ", str); } } /* resolve the links from the ajacent contour indices */ for(sliceNode = getListNode(slices,0); listSize(slices) > 1 &&((listNode*)sliceNode)->next; sliceNode = (listNode*) sliceNode->next) { /* get links to this slice list and the next, for searching */ slice = (list*) sliceNode->data; nextSlice = (list*) ((listNode*) ((listNode*)sliceNode)->next)->data; /* iterate over the contours in this slice */ for(contNode = getListNode(slice,0); contNode; contNode = (listNode*) contNode->next) { cont = (contour*) contNode->data; /* iterate over the adjacent contour indices */ for(adjNode = getListNode(cont->adjacentContours,0); adjNode; adjNode = (listNode*) adjNode->next) { /* get the index, replace it with a link, or NULL */ in = (intNode*) adjNode->data; lnAdj = getListNode(nextSlice,in->val); free(in); if(lnAdj == NULL) { markForDeletion(adjNode); } else { setListNodeData(adjNode, (void*) lnAdj->data); } } deleteMarkedNodes(cont->adjacentContours); } } fclose(fp); return slices; }
/** * do align specific drawing */ void alignDraw() { list *l, *cList = NULL; listNode *i,*j; vertex *t, *prev; quadri curPos; /* to hold current pos image to be displayed */ vector rc; /* world coords of rotation center */ //char slicefile1[MAX_STR_LEN]; float maxTexX, maxTexY; GLenum textureMethod = getTextureMethod(); /* draw the current referrence image */ if(curSlice != 0 && animate && displayImg == 0) { /* just display the reference image */ maxTexX = (float) ref->width; maxTexY = (float) ref->height; if(curDataset->imageSource != VP_NOIMAGES) { /* turn on texture mapping */ glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE); glEnable(textureMethod); /* bind the texture */ glBindTexture(textureMethod, *refTex); /* get the window coordinates of the reference image */ curPos = getWindowCoordsQ(refImgBounds); if(textureMethod == GL_TEXTURE_2D) { maxTexX = ref->width/(float)(ref->width+ref->padX); maxTexY = ref->height/(float)(ref->height+ref->padY); } /* make a quadrilateral and provide texture coords */ glBegin(GL_QUADS); { glTexCoord2d(0.0,0.0); glVertex3d(curPos.v1.x, curPos.v1.y, 0.0); glTexCoord2d(maxTexX,0.0); glVertex3d(curPos.v2.x, curPos.v2.y, 0.0); glTexCoord2d(maxTexX,maxTexY); glVertex3d(curPos.v3.x, curPos.v3.y, 0.0); glTexCoord2d(0.0,maxTexY); glVertex3d(curPos.v4.x, curPos.v4.y, 0.0); } glEnd(); glDisable(textureMethod); } } else if(curSlice == 0 || !animate || displayImg == 1) { /* apply the current rot & trans */ /* calculate transformed coordinates based on current rot and trans */ if(moving) { curPos = getQuadTranslation(movImgBounds, curTransAction); } else if(rotating) { /* rotate the movImg coords bu the current angle */ curPos = getQuadRotation(movImgBounds, curRotCenter, curRotAngle); } else { /* no current transformation, draw at expected location */ curPos = movImgBounds; } curPos = getWindowCoordsQ(curPos); maxTexX = (float) mov->width; maxTexY = (float) mov->height; if(curDataset->imageSource != VP_NOIMAGES) { if(textureMethod == GL_TEXTURE_2D) { maxTexX = mov->width/(float)(mov->width+mov->padX); maxTexY = mov->height/(float)(mov->height+mov->padY); } /* turn on texture mapping */ glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE); glEnable(textureMethod); /* bind the texture */ glBindTexture(textureMethod, *movTex); /* get the window coordinates of the moving image */ //curPos = getWindowCoordsQ(curPos); /* make a quadrilateral and provide texture coords */ glBegin(GL_QUADS); { glTexCoord2f(0,0); glVertex3d(curPos.v1.x, curPos.v1.y, 0); glTexCoord2f(maxTexX,0); glVertex3d(curPos.v2.x, curPos.v2.y, 0); glTexCoord2f(maxTexX,maxTexY); glVertex3d(curPos.v3.x, curPos.v3.y, 0); glTexCoord2f(0,maxTexY); glVertex3d(curPos.v4.x, curPos.v4.y, 0); } glEnd(); glDisable(textureMethod); } } /* cur slice contours and markers */ if(showCurTacks && listSize(curDataset->sliceContourLists) > curSlice) { glColor3fv(COLORS[DARK_GRAY]); /* iterate over contours, drawing each */ l = (list*)getListNode(curDataset->sliceContourLists,curSlice)->data; for(i = getListNode(l,0); i; i = (listNode*) i->next) { /* get the contour at index */ cList = ((contour*)i->data)->vertices; /* draw the contour lines, if we need to */ glPointSize(pixelSize*tackWidth); glBegin(GL_LINES); { /* iterate over tacks, drawing lines between each */ prev = listSize(cList) > 1 ? (vertex*) getListNode(cList,0)->data : NULL; for(j = getListNode(cList,1); prev && j; j = (listNode*) j->next) { t = (vertex*) j->data; drawLine(prev,t); prev = t; } } glEnd(); /* draw the tacks in the contour */ for(j = getListNode(cList,0); j; j = (listNode*) j->next) { t = (vertex*) j->data; /* draw the tack */ drawTack(t); } } /* cur slice markers */ glColor3fv(COLORS[GRAYED_LIGHT_ORANGE]); l = (list*)getListNode(curDataset->sliceMarkerLists,curSlice-1)->data; for(i = getListNode(l,0); i; i = (listNode*) i->next) { t = (vertex*) i->data; /* draw the tack */ drawTack(t); } } /* prev slice contours and markers */ if(showPrevTacks && curSlice > 0 && listSize(curDataset->sliceContourLists) > curSlice-1) { glColor3fv(COLORS[GRAY]); /* iterate over contours, drawing each */ l = ((contour*)getListNode(curDataset->sliceContourLists,curSlice-1)->data)->vertices; for(i = getListNode(l,0); i; i = (listNode*) i->next) { /* get the contour at index */ cList = (list*)i->data; /* draw the contour lines, if we need to */ glPointSize(pixelSize*tackWidth); glBegin(GL_LINES); { /* iterate over tacks, drawing lines between each */ prev = listSize(cList) > 1 ? (vertex*) getListNode(cList,0)->data : NULL; for(j = getListNode(cList,1); prev && j; j = (listNode*) j->next) { t = (vertex*) j->data; drawLine(prev,t); prev = t; } } glEnd(); /* draw the tacks in the contour */ for(j = getListNode(cList,0); j; j = (listNode*) j->next) { t = (vertex*) j->data; /* draw the tack */ drawTack(t); } } /* cur slice markers */ glColor3fv(COLORS[GRAYED_LIGHT_ORANGE]); l = (list*)getListNode(curDataset->sliceMarkerLists,curSlice-1)->data; for(i = getListNode(l,0); i; i = (listNode*) i->next) { t = (vertex*)i->data; /* draw the tack */ drawTack(t); } } /* draw the center of rotation */ glPointSize(rotCenterSize); glBegin(GL_POINTS); { glColor3fv(COLORS[RED]); rc = getWindowCoordsV(curRotCenter); glVertex3d(rc.x, rc.y, 0); } glEnd(); /* build info and alert strings */ //getSliceFilename(curDataset, curSlice, slicefile1); //getSliceFilename(curDataset, curSlice+1, slicefile2); strcpy(modeString,"align: "); sprintf(modeString,"slice %d ",curSlice); //strcat(modeString,slicefile1); //strcat(modeString," to "); //strcat(modeString,slicefile1); }
Void list_get_at(List list,int index){ ListNode head=list->nodes; ListNode node=getListNode(head,index); if (node==NULL) return NULL; return node->ele; }