BSTreeNode* ConvertNode(BSTreeNode* pNode, bool asRight) { if(!pNode) { return NULL; } BSTreeNode *pLeft = NULL; BSTreeNode *pRight = NULL; // left subtree exist, convert left subtree. if(pNode->m_pLeft) { pLeft = ConvertNode(pNode->m_pLeft, false); } // max left node link with pNode if(pLeft) { pLeft->m_pRight = pNode; pNode->m_pLeft = pLeft; } // right subtree exist, convert right subtree if(pNode->m_pRight) { pRight = ConvertNode(pNode->m_pRight, true); } // min right node link with pNode if(pRight) { pRight->m_pLeft = pNode; pNode->m_pRight = pRight; } BSTreeNode *pTemp = pNode; if(asRight) { // find min tree node for right tree while(pTemp->m_pLeft) { pTemp = pTemp->m_pLeft; } } else { // find max tree node for left tree while(pTemp->m_pRight) { pTemp = pTemp->m_pRight; } } return pTemp; }
AtObj AtlasObject::LoadFromJSON(JSContext* cx, const std::string& json) { // Convert UTF8 to UTF16 wxString jsonW(json.c_str(), wxConvUTF8); size_t json16len; wxCharBuffer json16 = wxMBConvUTF16().cWC2MB(jsonW.c_str(), jsonW.Length(), &json16len); jsval vp = JSVAL_NULL; JSONParser* parser = JS_BeginJSONParse(cx, &vp); if (!parser) { wxLogError(_T("ParseJSON failed to begin")); return AtObj(); } if (!JS_ConsumeJSONText(cx, parser, reinterpret_cast<const jschar*>(json16.data()), (uint32)(json16len/2))) { wxLogError(_T("ParseJSON failed to consume")); return AtObj(); } if (!JS_FinishJSONParse(cx, parser, JSVAL_NULL)) { wxLogError(_T("ParseJSON failed to finish")); return AtObj(); } AtObj obj; obj.p = ConvertNode(cx, vp); return obj; }
void WriteStdoutRamaOneModel(PMSD pmsdRoot, Int2 ModelNum ){ ValNodePtr vnpRama = NULL; PRS prsHead = NULL; PRS prsHere = NULL; float phi,psi; int num; Int4 linelen; Char aa[3]; Char ctemp[30]; Char chain[30]; PMGD pmgdAA = NULL; CharPtr NCBIstdaaUC = "-ABCDEFGHIKLMNPQRSTVWXYZU*"; vnpRama=ConvertNode((PFB)pmsdRoot,AM_MGD); if (vnpRama==NULL) return; prsHead=Rama(vnpRama,ModelNum); prsHere=prsHead; while(prsHere) { phi = 0.0; psi = 0.0; phi=(float)prsHere->Phi; psi=(float)prsHere->Psi; pmgdAA = (PMGD) prsHere->pfbThis; num = (int) (pmgdAA->pdnmgLink->choice); StringCpy(ctemp, StringChr(NCBIstdaaUC,pmgdAA->pcIUPAC[0])); StringCpy(chain, ParentMolName((PFB) pmgdAA)); aa[0] = ctemp[0]; aa[1] = '\0'; printf("%s, %s, %d, %f, %f\n", chain, aa , (int) num, phi,psi); prsHere=prsHere->next; } freeRS(prsHead); return; }
void ConvertNode(TreeNode* pRoot, TreeNode** lastNode) { if(pRoot == NULL) return; TreeNode* pCur = pRoot; if(pCur->left) ConvertNode(pRoot->left, lastNode); pCur->left = *lastNode; if(*lastNode) { (*lastNode)->right = pCur; } *lastNode = pCur; if(pCur->right) ConvertNode(pRoot->right, lastNode); }
AtObj AtlasObject::LoadFromJSON(const std::string& json) { json_spirit::Value rootnode; json_spirit::read_string(json, rootnode); AtObj obj; obj.p = ConvertNode(rootnode); return obj; }
void *ConvertNode(NODE *pnode , NODE *lastnode){ if(pnode = NULL) return ; NODE *temp= pnode; if(temp->left !=NULL) ConvertNode(temp->left,lastnode ); temp->left = lastnode; if(lastnode != NULL) lastnode->right = temp; lastnode = temp; if(temp->right != NULL) ConvertNode(temp->right , lastnode); }
void ConvertNode(BinaryTreeNode* pNode, BinaryTreeNode** pLastNodeInList) { if(pNode == NULL) return; BinaryTreeNode *pCurrent = pNode; if (pCurrent->m_pLeft != NULL) ConvertNode(pCurrent->m_pLeft, pLastNodeInList); pCurrent->m_pLeft = *pLastNodeInList; if(*pLastNodeInList != NULL) (*pLastNodeInList)->m_pRight = pCurrent; *pLastNodeInList = pCurrent; if (pCurrent->m_pRight != NULL) ConvertNode(pCurrent->m_pRight, pLastNodeInList); }
NODE * Convert_Solution(NODE * ptrHead){ NODE *temp = NULL; ConvertNode(ptrHead , lastnode); NODE * headlist=lastnode; while(headlist && headlist->left) headlist = headlist->left; return headlist; }
// convert a binary search tree into a sorted double-lined list // input: pHeadOfTree - the head of tree // output: the head of sorted double-linked list BSTreeNode* Convert_Solution2(BSTreeNode* pHeadOfTree){ BSTreeNode* pLastNodeInList = NULL; ConvertNode(pHeadOfList, pLastNodeInList); // get the head of the double-linked list BSTreeNode* pHeadOfList = pLastNodeInList; while(pHeadOfList && pHeadOfList->m_pLeft) pHeadOfList = pHeadOfList->m_pLeft; return pHeadOfList; }
// // // CONVERT // top level conversion: recursive descent on the node and children // for each node, search for segments to convert... // // bool plAnimAvatarComponent::Convert(plMaxNode *node, plErrorMsg *pErrMsg) { Interface *theInterface = node->GetInterface(); RemoveBiped(node, theInterface); ConvertNode(node, pErrMsg); ((plSceneNode *)node->GetRoomKey()->GetObjectPtr())->SetFilterGenericsOnly(true); return true; }
void ConvertNode(BinarryTree* pNode, BinarryTree** pLastNodeInList) { if(pNode==NULL) return; BinarryTree* pCurrent = pNode; //递归的链接好左子树 if(pCurrent->m_pLeft!=NULL) ConvertNode(pCurrent->m_pLeft, pLastNodeInList); //把pCurrent纳入链表 pCurrent->m_pLeft = *pLastNodeInList; if(*pLastNodeInList!=NULL) (*pLastNodeInList)->m_pRight = pCurrent; *pLastNodeInList = pCurrent; //递归的链接好右子树 if(pCurrent->m_pRight!=NULL) ConvertNode(pCurrent->m_pRight, pLastNodeInList); }
void ConvertNode(BSTreeNode* pNode, BSTreeNode*& pLastNodeInList){ if(pNode == NULL) return; BSTreeNode* pCurrent = pNode; // convert the left sub-tree if(pCurrent->m_pLeft != NULL) ConvertNode(pCurrent->m_pLeft, pLastNodeInList); // put the current node into the double-linked list pCurrent->m_pLeft = pLastNodeInList; if(pLastNodeInList != NULL) pLastNodeInList->m_pRight = pCurrent; pLastNodeInList = pCurrent; // convert the right sub-tree if(pCurrent->m_pRight != NULL) ConvertNode(pCurrent->m_pRight, pLastNodeInList); }
BSTreeNode* ConvertNode(BSTreeNode* pNode, bool asRight){ if(!pNode) return NULL; BSTreeNode* pLeft = NULL; BSTreeNode* pRight = NULL; // convert the left sub-tree if(pNode->m_pLeft) pLeft = ConvertNode(pNode->m_pLeft, false); // connect the greatest node in the left sib-tree to the current node if(pLeft){ pLeft->m_pLeft = pNode; pNode->m_pLeft = pLeft; } // convert the right sub-tree if(pNode->m_pRight) pRight = ConvertNode(pNode->m_pRight, true); // connect the least node in the right sub-tree to the current node. if(pRight){ pNode->m_pRight = pRight; pRight->m_pLeft = pNode; } BSTreeNode* pTemp = pNode; // if the current node is the right child of its parent, // return the least node in the tree whose root is the current node if(asRight){ while(pTemp->m_pLeft) pTemp = pTemp->m_pLeft; } // if the current node is the left child of its parent, // return the greatest node in the tree whose root is the current nde else{ while(pTemp->m_pRight){ pTemp = pTemp->m_pRight; } } return pTemp; }
TreeNode* Convert(TreeNode* pRootOfTree) { if(pRootOfTree == NULL) return NULL; TreeNode* lastNode = NULL; ConvertNode(pRootOfTree, &lastNode); TreeNode* pHead = lastNode; while(pHead && pHead->left) pHead = pHead->left; return pHead; }
TreeNode* Convert(TreeNode* pRootOfTree) { TreeNode* pLastNodeInList = NULL; ConvertNode(pRootOfTree, &pLastNodeInList); // return the head pointer TreeNode* pHeadOfList = pLastNodeInList; while (pHeadOfList != NULL && pHeadOfList->left != NULL) { pHeadOfList = pHeadOfList->left; } return pHeadOfList; }
BinaryTreeNode* Convert(BinaryTreeNode* pRootOfTree) { BinaryTreeNode *pLastNodeInList = NULL; ConvertNode(pRootOfTree, &pLastNodeInList); // pLastNodeInListÖ¸ÏòË«ÏòÁ´±íµÄβ½áµã£¬ // ÎÒÃÇÐèÒª·µ»ØÍ·½áµã BinaryTreeNode *pHeadOfList = pLastNodeInList; while(pHeadOfList != NULL && pHeadOfList->m_pLeft != NULL) pHeadOfList = pHeadOfList->m_pLeft; return pHeadOfList; }
BinaryTreeNode* Convert(BinaryTreeNode* pRootOfTree) { BinaryTreeNode *pLastNodeInList = NULL; ConvertNode(pRootOfTree, &pLastNodeInList); // pLastNodeInList指向双向链表的尾结点, // 我们需要返回头结点 BinaryTreeNode *pHeadOfList = pLastNodeInList; while(pHeadOfList != NULL && pHeadOfList->m_pLeft != NULL) pHeadOfList = pHeadOfList->m_pLeft; return pHeadOfList; }
// Convert ------------------------------------------------------------ // -------- bool plEmoteComponent::Convert(plMaxNode *node, plErrorMsg *pErrMsg) { Interface *theInterface = node->GetInterface(); RemoveBiped(node, theInterface); fFadeIn = fCompPB->GetFloat(kFadeIn); fFadeOut = fCompPB->GetFloat(kFadeOut); fBodyUsage = static_cast<plEmoteAnim::BodyUsage>(fCompPB->GetInt(kBodyUsage)); ConvertNode(node, pErrMsg); ((plSceneNode *)node->GetRoomKey()->GetObjectPtr())->SetFilterGenericsOnly(true); return true; }
void ConvertNode(TreeNode* pNode, TreeNode** pLastNodeInList) { if (pNode == NULL) { return; } TreeNode* pCurrent = pNode; if (pCurrent->left != NULL) { ConvertNode(pCurrent->left, pLastNodeInList); } pCurrent->left = *pLastNodeInList; if (*pLastNodeInList != NULL) { (*pLastNodeInList)->right = pCurrent; } *pLastNodeInList = pCurrent; if (pCurrent->right != NULL) { ConvertNode(pCurrent->right, pLastNodeInList); } }
void LeftHandConvertor::ConvertNode( aiNode* node ) { node->mTransformation.b1 = -node->mTransformation.b1; node->mTransformation.b3 = -node->mTransformation.b3; node->mTransformation.b4 = -node->mTransformation.b4; node->mTransformation.a2 = -node->mTransformation.a2; node->mTransformation.c2 = -node->mTransformation.c2; node->mTransformation.d2 = -node->mTransformation.d2; for( std::size_t i=0; i < node->mNumChildren; ++i ) { ConvertNode( node->mChildren[i] ); } }
/* 函数功能:把二叉搜索树变双向链表 参数:二叉搜索树的根结点指针 返回值:双向链表的头结点指针 步骤: 1.特殊输入判断 2.先处理好左子树,再连接根结点,再处理右子树(分制法)。递归 */ DoubleLink* Convert(BinarryTree* pTreeRoot) { if(pTreeRoot==NULL) return ; //pLastNodeInList指向链表的尾部 BinarryTree* pLastNodeInList = NULL; ConvertNode(pTreeRoot, &pLastNodeInList); //用pLastNodeInList倒回去得到pHeadInList BinarryTree* pHeadOfList = pLastNodeInList; while(pHeadOfList!=NULL && pHeadOfList->m_pLeft!=NULL) pHeadOfList = pHeadOfList->m_pLeft; return pHeadOfList; }
// // CONVERTNODE // look for all the segments on this node and convert them // recurse on children // // bool plAnimAvatarComponent::ConvertNode(plMaxNode *node, plErrorMsg *pErrMsg) { plNotetrackAnim noteAnim(node, pErrMsg); // does this node have any segments specified? if (noteAnim.HasNotetracks()) { // for each segment we found: plString animName; while (!(animName = noteAnim.GetNextAnimName()).IsNull()) { plAnimInfo info = noteAnim.GetAnimInfo(animName); plATCAnim *anim = NewAnimation(info.GetAnimName(), info.GetAnimStart(), info.GetAnimEnd()); plString loopName = info.GetNextLoopName(); if (!loopName.IsNull()) { anim->SetLoop(true); float loopStart = info.GetLoopStart(loopName); float loopEnd = info.GetLoopEnd(loopName); anim->SetLoopStart(loopStart == -1 ? anim->GetStart() : loopStart); anim->SetLoopEnd(loopEnd == -1 ? anim->GetEnd() : loopEnd); } plString marker; while (!(marker = info.GetNextMarkerName()).IsNull()) anim->AddMarker(marker, info.GetMarkerTime(marker)); ConvertNodeSegmentBranch(node, anim, pErrMsg); MakePersistent(node, anim, info.GetAnimName(), pErrMsg); } } // let's see if the children have any segments specified... int childCount = node->NumberOfChildren(); for (int i = 0; i < childCount; i++) ConvertNode((plMaxNode *)(node->GetChildNode(i)), pErrMsg); return true; }
void LeftHandConvertor::ProcessScene() { ConvertNode( mAssimpScene->mRootNode ); for( std::size_t i=0; i < mAssimpScene->mNumMeshes; ++i ) { ConvertMesh( mAssimpScene->mMeshes[i] ); } for( std::size_t i=0; i < mAssimpScene->mNumMaterials; ++i ) { ConvertMaterial( mAssimpScene->mMaterials[i] ); } for ( std::size_t i=0; i < mAssimpScene->mNumAnimations; ++i ) { aiAnimation* animation = mAssimpScene->mAnimations[i]; for( std::size_t j=0; j < animation->mNumChannels; ++j ) { aiNodeAnim* nodeAnimation = animation->mChannels[j]; ConvertAnimation( nodeAnimation ); } } }
// Convert from a jsval to an AtNode static AtSmartPtr<AtNode> ConvertNode(JSContext* cx, jsval node) { AtSmartPtr<AtNode> obj (new AtNode()); // Non-objects get converted into strings if (!JSVAL_IS_OBJECT(node)) { JSString* str = JS_ValueToString(cx, node); if (!str) return obj; // error size_t valueLen; const jschar* valueChars = JS_GetStringCharsAndLength(cx, str, &valueLen); if (!valueChars) return obj; // error wxString valueWx(reinterpret_cast<const char*>(valueChars), wxMBConvUTF16(), valueLen*2); obj->value = valueWx.c_str(); // Annotate numbers/booleans specially, to allow round-tripping if (JSVAL_IS_NUMBER(node)) { obj->children.insert(AtNode::child_pairtype( "@number", AtSmartPtr<AtNode>(new AtNode()) )); } else if (JSVAL_IS_BOOLEAN(node)) { obj->children.insert(AtNode::child_pairtype( "@boolean", AtSmartPtr<AtNode>(new AtNode()) )); } return obj; } JSObject* it = JS_NewPropertyIterator(cx, JSVAL_TO_OBJECT(node)); if (!it) return obj; // error while (true) { jsid idp; jsval val; if (! JS_NextProperty(cx, it, &idp) || ! JS_IdToValue(cx, idp, &val)) return obj; // error if (val == JSVAL_VOID) break; // end of iteration if (! JSVAL_IS_STRING(val)) continue; // ignore integer properties JSString* name = JSVAL_TO_STRING(val); size_t len; const jschar* chars = JS_GetStringCharsAndLength(cx, name, &len); wxString nameWx(reinterpret_cast<const char*>(chars), wxMBConvUTF16(), len*2); std::string nameStr(nameWx.ToUTF8().data()); jsval vp; if (!JS_GetPropertyById(cx, JSVAL_TO_OBJECT(node), idp, &vp)) return obj; // error // Unwrap arrays into a special format like <$name><item>$i0</item><item>... // (This assumes arrays aren't nested) if (JSVAL_IS_OBJECT(vp) && JS_IsArrayObject(cx, JSVAL_TO_OBJECT(vp))) { AtSmartPtr<AtNode> child(new AtNode()); child->children.insert(AtNode::child_pairtype( "@array", AtSmartPtr<AtNode>(new AtNode()) )); jsuint arrayLength; if (!JS_GetArrayLength(cx, JSVAL_TO_OBJECT(vp), &arrayLength)) return obj; // error for (jsuint i = 0; i < arrayLength; ++i) { jsval val; if (!JS_GetElement(cx, JSVAL_TO_OBJECT(vp), i, &val)) return obj; // error child->children.insert(AtNode::child_pairtype( "item", ConvertNode(cx, val) )); } obj->children.insert(AtNode::child_pairtype( nameStr, child )); } else { obj->children.insert(AtNode::child_pairtype( nameStr, ConvertNode(cx, vp) )); } } return obj; }
BSTreeNode* Convert(BSTreeNode* pHeadOfTree) { return ConvertNode(pHeadOfTree, true); }
// convert a binary search tree into a sorted double-linked list // input: the head of tree // output: the head of sorted double-linked list BSTreeNode* Convert(BSTreeNode* pHeadOfTree){ // as we want to return the head of the sorted double-linked list, // we set the second parameter to be true return ConvertNode(pHeadOfTree, true); }
// Convert from a JSON to an AtNode static AtSmartPtr<AtNode> ConvertNode(json_spirit::Value node) { AtSmartPtr<AtNode> obj (new AtNode()); if (node.type() == json_spirit::str_type) { obj->value = std::wstring(node.get_str().begin(),node.get_str().end()); } else if (node.type() == json_spirit::int_type || node.type() == json_spirit::real_type) { std::wstringstream stream; if (node.type() == json_spirit::int_type) stream << node.get_int(); if (node.type() == json_spirit::real_type) stream << node.get_real(); obj->value = stream.str().c_str(); obj->children.insert(AtNode::child_pairtype( "@number", AtSmartPtr<AtNode>(new AtNode()) )); } else if (node.type() == json_spirit::bool_type) { if (node.get_bool()) obj->value = L"true"; else obj->value = L"false"; obj->children.insert(AtNode::child_pairtype( "@boolean", AtSmartPtr<AtNode>(new AtNode()) )); } else if (node.type() == json_spirit::array_type) { obj->children.insert(AtNode::child_pairtype( "@array", AtSmartPtr<AtNode>(new AtNode()) )); json_spirit::Array nodeChildren = node.get_array(); json_spirit::Array::iterator itr = nodeChildren.begin(); for (; itr != nodeChildren.end(); itr++) { obj->children.insert(AtNode::child_pairtype( "item", ConvertNode(*itr) )); } } else if (node.type() == json_spirit::obj_type) { json_spirit::Object objectProperties = node.get_obj(); json_spirit::Object::iterator itr = objectProperties.begin(); for (; itr != objectProperties.end(); itr++) { obj->children.insert(AtNode::child_pairtype( itr->name_, ConvertNode(itr->value_) )); } } else if (node.type() == json_spirit::null_type) { return obj; } else { assert(! "Unimplemented type found when parsing JSON!"); } return obj; }