示例#1
0
文件: GiST.cpp 项目: jsc0218/MxTree
void 
GiST::OverflowTreatment (GiSTnode *node, const GiSTentry& entry, int *splitvec)
{
	// remove the "top" p entries from the node
	GiSTlist<GiSTentry*> deleted = RemoveTop (node);
	WriteNode (node);
	AdjustKeys (node, NULL);
	// note that we've seen this level already
	splitvec[node->Level()] = 1;
	// for each of the deleted entries, call InsertHelper at this level
	while (!deleted.IsEmpty()) {
		GiSTentry *tmpentry = deleted.RemoveFront ();
		InsertHelper (*tmpentry, node->Level(), splitvec);
		delete tmpentry;
	}
}
示例#2
0
void DisplaySubst()
{
NODE *n;

  n = substList;
  substENABLED = 0;
  while( n != 0 ) {
    printf("Subst: ");
    WriteElm( n );
    printf( " --> " );    
    WriteNode( n->right );
    printf("\n");
    n = n->left;
  }
  substENABLED = 1;
}
示例#3
0
gxDatabaseError BtreeBucket::Flush(gxDatabase *f) 
// Function used to flush this bucket to disk and reset the 
// bucket variables. Returns zero if successful or a non-zero 
// value to indicate a failure.
{ 
  gxDatabaseError err = gxDBASE_NO_ERROR;
  if((node_address != (FAU_t)0) && (is_dirty == 1)) {
    err = WriteNode(f);
    if(err == gxDBASE_NO_ERROR) {
      key_count = (BtreeKeyCount_t)0; // Reset the key count
      node_address = (FAU_t)0;        // Reset the node's file offset 
      is_dirty = 0;                   // Reset the dirty flag
    }
  }
  return err;
}
示例#4
0
  void XmlWriter::WriteElement(const Element& rElement)
  {
    WriteIndent();
    m_rStream << "<" << rElement.GetPrefixName();

    // write namespaces
    for (const Namespace* pNamespace = rElement.GetFirstNamespace();
         pNamespace; pNamespace = pNamespace->GetNextSibling())
    {
      WriteNamespace(*pNamespace);
    }

    // write attributes
    for (const Attribute* pAttribute = rElement.GetFirstAttribute();
         pAttribute; pAttribute = pAttribute->GetNextSibling())
    {
      WriteAttribute(*pAttribute);
    }

    if (rElement.IsEmpty())
    {
      // end element
      m_rStream << "/>";
    }
    else
    {
      m_rStream << ">";

      if (rElement.IsLeaf())
      {
        WriteText(static_cast<const Text&>(*rElement.GetFirstChild()));
      }
      else
      {
        // write childs

        ++m_nIndent;
        for (const Node* pNode = rElement.GetFirstChild(); pNode; pNode = pNode->GetNextSibling())
        {
          WriteNode(*pNode);
        }
        --m_nIndent;
        WriteIndent();
      }
      m_rStream << "</" << rElement.GetPrefixName() << ">";
    }
  }
示例#5
0
文件: GiST.cpp 项目: voidcycles/m3
void 
GiST::Create(const char *filename)
{
	GiSTpage page;

	if(IsOpen()) return;
	store=CreateStore();
	store->Create(filename);
	if(!store->IsOpen()) return;
	page=store->Allocate();

	GiSTnode *node=NewNode(this);
	node->Path().MakeRoot();
	WriteNode(node);
	delete node;
	isOpen=1;
}
示例#6
0
// -----------------------------------------------------------------------------------
// Write a single node as text dump
void WriteNode(const aiNode* node, FILE* out, unsigned int depth)
{
	char prefix[512];
	for (unsigned int i = 0; i < depth;++i)
		prefix[i] = '\t';
	prefix[depth] = '\0';

	const aiMatrix4x4& m = node->mTransformation;

	aiString name;
	ConvertName(name,node->mName);
	fprintf(out,"%s<Node name=\"%s\"> \n"
		"%s\t<Matrix4> \n"
		"%s\t\t%0 6f %0 6f %0 6f %0 6f\n"
		"%s\t\t%0 6f %0 6f %0 6f %0 6f\n"
		"%s\t\t%0 6f %0 6f %0 6f %0 6f\n"
		"%s\t\t%0 6f %0 6f %0 6f %0 6f\n"
		"%s\t</Matrix4> \n",
		prefix,name.data,prefix,
		prefix,m.a1,m.a2,m.a3,m.a4,
		prefix,m.b1,m.b2,m.b3,m.b4,
		prefix,m.c1,m.c2,m.c3,m.c4,
		prefix,m.d1,m.d2,m.d3,m.d4,prefix);

	if (node->mNumMeshes) {
		fprintf(out, "%s\t<MeshRefs num=\"%i\">\n%s\t",
			prefix,node->mNumMeshes,prefix);

		for (unsigned int i = 0; i < node->mNumMeshes;++i) {
			fprintf(out,"%i ",node->mMeshes[i]);
		}
		fprintf(out,"\n%s\t</MeshRefs>\n",prefix);
	}

	if (node->mNumChildren) {
		fprintf(out,"%s\t<NodeList num=\"%i\">\n",
			prefix,node->mNumChildren);

		for (unsigned int i = 0; i < node->mNumChildren;++i) {
			WriteNode(node->mChildren[i],out,depth+2);
		}
		fprintf(out,"%s\t</NodeList>\n",prefix);
	}
	fprintf(out,"%s</Node>\n",prefix);
}
示例#7
0
文件: GiST.cpp 项目: jsc0218/MxTree
void 
GiST::Create (const char *filename)
{
	if (IsOpen()) {
		return;
	}
	store = CreateStore();
	store->Create(filename);
	if (!store->IsOpen()) {  // create failed!
		return;
	}
	store->Allocate();  // added by myself, reserved for root
	store->Allocate();
	GiSTnode *node = NewNode(this);
	node->Path().MakeRoot();
	WriteNode (node);
	delete node;
	isOpen = 1;
}
示例#8
0
文件: MXTree.cpp 项目: jsc0218/MxTree
void MXTree::Create(const char *filename)
{
	if (IsOpen()) {
		return;
	}
	store = CreateStore();
	store->Create(filename);
	if (!store->IsOpen()) { 
		return;
	}
	store->Allocate();  // reserved for root pointer
	rootPage = store->Allocate();
	assert(rootPage == 1);
	GiSTnode *node = NewNode(this);
	node->Path().MakeRoot();
	WriteNode(node);
	delete node;
	isOpen = 1;
}
示例#9
0
文件: GiST.cpp 项目: voidcycles/m3
void
GiST::ShortenTree()
{
	GiSTpath path;
	// Shorten the tree if necessary (This should only be done if root actually changed!)
	path.MakeRoot();
	GiSTnode *root=ReadNode(path);

	if(!root->IsLeaf()&&root->NumEntries()==1) {
		path.MakeChild((*root)[0]->Ptr());
		GiSTnode *child=ReadNode(path);

		store->Deallocate(path.Page());
		child->SetSibling(0);
		child->Path().MakeRoot();
		WriteNode(child);
		delete child;
	}
	delete root;
}
示例#10
0
void ExpandElm( NODE * n )
{
NODE *cn;

  if( substENABLED == 0 ) {
    WriteElm( n );
    return;
  }   
  cn = LookUpSubst( n );
  if( cn == 0 ) {
    WriteElm( n );
  } else {
    if( cn->type > SUBST ) {
      WriteElm( n );
    } else {
      cn->type += SUBST;
      WriteSymbol( O_PAREN );
      WriteNode( cn->right );       
      WriteSymbol( C_PAREN );
      cn->type -= SUBST;
    }
  }
}
示例#11
0
文件: GiST.cpp 项目: voidcycles/m3
// handle underfull leaf nodes
int
GiST::CondenseTree(GiSTnode *node)
{
	GiSTlist<GiSTentry*> Q;
	int deleted=0;

	// Must be condensing a leaf
	assert(node->IsLeaf());
	while(!node->Path().IsRoot()) {
		GiSTpath parent_path=node->Path();
		parent_path.MakeParent();
		GiSTnode *P=ReadNode(parent_path);
		GiSTentry *En=P->SearchPtr(node->Path().Page());

		assert(En!=NULL);
		// Handle under-full node
		if(node->IsUnderFull(*store)) {
		    if(!IsOrdered()) {
				TruePredicate truePredicate;
				GiSTlist<GiSTentry*> list=node->Search(truePredicate);

				while(!list.IsEmpty()) {
					GiSTentry *e=list.RemoveFront();

					Q.Append(e);
				}
				P->DeleteEntry(En->Position());
				WriteNode(P);
				deleted=1;
				AdjustKeys(P, NULL);
			}
			else {
				// Try to borrow entries, else coalesce with a neighbor
				// Have to look at left sibling???
				GiSTpage neighbor_page=P->SearchNeighbors(node->Path().Page());
				GiSTpath neighbor_path=node->Path();

				neighbor_path.MakeSibling(neighbor_page);
				if(neighbor_page!=0) {
					GiSTnode *neighbor;

					// If neighbor is RIGHT sibling...
					if(node->Sibling()==neighbor_page) neighbor=ReadNode(neighbor_path);
                    else {
						neighbor=node;
						node=ReadNode(neighbor_path);
					}

					GiSTentry *e=P->SearchPtr(node->Path().Page());

					node->Coalesce(*neighbor, *e);
					delete e;
					// If not overfull, coalesce, kill right node
					if(!node->IsOverFull(*store)) {
						node->SetSibling(neighbor->Sibling());
						WriteNode(node);

						// Delete the neighbor from parent
						GiSTentry *e=P->SearchPtr(neighbor->Path().Page());

						P->DeleteEntry(e->Position());
						WriteNode(P);
						delete e;
						store->Deallocate(neighbor->Path().Page());
						deleted=1;
					}
					// If overfull, split (same as borrowing)
					else {
						GiSTnode *node2=node->PickSplit();

						node2->Path()=neighbor->Path();
						node2->SetSibling(neighbor->Sibling());
						WriteNode(node);
						WriteNode(node2);
						AdjustKeys(node2, &P);
						delete node2;
						deleted=1;
					}
					delete neighbor;
				}
			}
		}
		// Adjust covering predicate
		if(!deleted) AdjustKeys(node, &P);
		parent_path=node->Path();
		parent_path.MakeParent();
		delete node;
		// Propagate deletes
		if(!deleted) break;
		node=P;
	}
	// Re-insert orphaned entries
	while(!Q.IsEmpty()) {
		GiSTentry *e=Q.RemoveFront();

		InsertHelper(*e, e->Level());
		delete e;
	}
	return(deleted);
}
示例#12
0
/* entry point to write a file
 * same as Write Node except it initializes the indent
 */
void xmlWriteFile(FILE *out, struct xmlNode *root)
{
    WriteNode(out,root,0) ;
}
示例#13
0
//-----------------------------------------------------------------------------
web::json::value gltfWriter::WriteNull (FbxNode *pNode) {
	web::json::value node =WriteNode (pNode) ;
	web::json::value ret =web::json::value::object ({ { U("nodes"), node } }) ;
	return (ret) ;
}
nsresult
sbFileSystemTreeState::SaveTreeState(sbFileSystemTree *aTree,
                                     const nsID & aSessionID)
{
  NS_ENSURE_ARG_POINTER(aTree);

  // Setup and write the serialized data as defined above.
  nsresult rv;
  nsCOMPtr<nsIFile> savedSessionFile;
  rv = GetTreeSessionFile(aSessionID, 
                          PR_TRUE,  // do create
                          getter_AddRefs(savedSessionFile));
  NS_ENSURE_SUCCESS(rv, rv);

  nsRefPtr<sbFileObjectOutputStream> fileObjectStream =
    new sbFileObjectOutputStream();
  NS_ENSURE_TRUE(fileObjectStream, NS_ERROR_OUT_OF_MEMORY);

  rv = fileObjectStream->InitWithFile(savedSessionFile);
  NS_ENSURE_SUCCESS(rv, rv);

  // Now begin to write out the data in the sequence described above:
  // 1.) The tree schema version.
  rv = fileObjectStream->WriteUint32(TREE_SCHEMA_VERSION);
  NS_ENSURE_SUCCESS(rv, rv);

  // 2.) Tree root absolute path
  rv = fileObjectStream->WriteString(aTree->mRootPath);
  NS_ENSURE_SUCCESS(rv, rv);

  // 3.) Is tree recursive watch.
  rv = fileObjectStream->WritePRBool(aTree->mIsRecursiveBuild);
  NS_ENSURE_SUCCESS(rv, rv);

  // 4.) Number of nodes
  PRUint32 nodeCount = 0;
  rv = GetTreeNodeCount(aTree->mRootNode, &nodeCount);
  NS_ENSURE_SUCCESS(rv, rv);

  rv = fileObjectStream->WriteUint32(nodeCount);
  NS_ENSURE_SUCCESS(rv, rv);

  // 5.) Node data
  std::stack<nsRefPtr<sbFileSystemNode> > nodeStack;
  nodeStack.push(aTree->mRootNode);

  // Used to create a unique identifier for a parent node.
  // NOTE: The root node will always be 0.
  PRUint32 curNodeID = 0;

  while (!nodeStack.empty()) {
    nsRefPtr<sbFileSystemNode> curNode = nodeStack.top();
    nodeStack.pop();

    if (!curNode) {
      NS_WARNING("Coult not get the node from the node stack!");
      continue;
    }

    // Set the id of the current node.
    rv = curNode->SetNodeID(curNodeID);
    if (NS_FAILED(rv)) {
      NS_WARNING("Could not set the node ID!");
      continue;
    }

    rv = WriteNode(fileObjectStream, curNode);
    if (NS_FAILED(rv)) {
      NS_WARNING("Could not write curNode to disk!");
      continue;
    }

    sbNodeMap *curNodeChildren = curNode->GetChildren();
    if (curNodeChildren && curNodeChildren->size() > 0) {
      // Iterate through the entire child node map to set the parent ID 
      // and push each node into the node stack.
      sbNodeMapIter begin = curNodeChildren->begin();
      sbNodeMapIter end = curNodeChildren->end();
      sbNodeMapIter next;
      for (next = begin; next != end; ++next) {
        nsRefPtr<sbFileSystemNode> curChildNode(next->second);
        if (!curChildNode) {
          NS_WARNING("Could not get get curChildNode!");
          continue;
        }

        rv = curChildNode->SetParentID(curNodeID);
        if (NS_FAILED(rv)) {
          NS_WARNING("Could not set the parent GUID!");
          continue;
        }

        nodeStack.push(curChildNode);
      } 
    }

    // Bump the node ID count.
    ++curNodeID;
  }

  rv = fileObjectStream->Close();
  NS_ENSURE_SUCCESS(rv, rv);

  return NS_OK;
}
示例#15
0
// -----------------------------------------------------------------------------------
// Write a text model dump
void WriteDump(const aiScene* scene, FILE* out, const char* src, const char* cmd, bool shortened)
{
	time_t tt = ::time(NULL);
	tm* p     = ::gmtime(&tt);

	std::string c = cmd;
	std::string::size_type s; 

	// https://sourceforge.net/tracker/?func=detail&aid=3167364&group_id=226462&atid=1067632
	// -- not allowed in XML comments
	while((s = c.find("--")) != std::string::npos) {
		c[s] = '?';
	}
	aiString name;

	// write header
	fprintf(out,
		"<?xml version=\"1.0\" encoding=\"utf-8\"?>\n"
		"<ASSIMP format_id=\"1\">\n\n"

		"<!-- XML Model dump produced by assimp dump\n"
		"  Library version: %i.%i.%i\n"
		"  Source: %s\n"
		"  Command line: %s\n"
		"  %s\n"
		"-->"
		" \n\n"
		"<Scene flags=\"%i\" postprocessing=\"%i\">\n",
		
		aiGetVersionMajor(),aiGetVersionMinor(),aiGetVersionRevision(),src,c.c_str(),asctime(p),
		scene->mFlags,
		0 /*globalImporter->GetEffectivePostProcessing()*/);

	// write the node graph
	WriteNode(scene->mRootNode, out, 0);

#if 0
		// write cameras
	for (unsigned int i = 0; i < scene->mNumCameras;++i) {
		aiCamera* cam  = scene->mCameras[i];
		ConvertName(name,cam->mName);

		// camera header
		fprintf(out,"\t<Camera parent=\"%s\">\n"
			"\t\t<Vector3 name=\"up\"        > %0 8f %0 8f %0 8f </Vector3>\n"
			"\t\t<Vector3 name=\"lookat\"    > %0 8f %0 8f %0 8f </Vector3>\n"
			"\t\t<Vector3 name=\"pos\"       > %0 8f %0 8f %0 8f </Vector3>\n"
			"\t\t<Float   name=\"fov\"       > %f </Float>\n"
			"\t\t<Float   name=\"aspect\"    > %f </Float>\n"
			"\t\t<Float   name=\"near_clip\" > %f </Float>\n"
			"\t\t<Float   name=\"far_clip\"  > %f </Float>\n"
			"\t</Camera>\n",
			name.data,
			cam->mUp.x,cam->mUp.y,cam->mUp.z,
			cam->mLookAt.x,cam->mLookAt.y,cam->mLookAt.z,
			cam->mPosition.x,cam->mPosition.y,cam->mPosition.z,
			cam->mHorizontalFOV,cam->mAspect,cam->mClipPlaneNear,cam->mClipPlaneFar,i);
	}

	// write lights
	for (unsigned int i = 0; i < scene->mNumLights;++i) {
		aiLight* l  = scene->mLights[i];
		ConvertName(name,l->mName);

		// light header
		fprintf(out,"\t<Light parent=\"%s\"> type=\"%s\"\n"
			"\t\t<Vector3 name=\"diffuse\"   > %0 8f %0 8f %0 8f </Vector3>\n"
			"\t\t<Vector3 name=\"specular\"  > %0 8f %0 8f %0 8f </Vector3>\n"
			"\t\t<Vector3 name=\"ambient\"   > %0 8f %0 8f %0 8f </Vector3>\n",
			name.data,
			(l->mType == aiLightSource_DIRECTIONAL ? "directional" :
			(l->mType == aiLightSource_POINT ? "point" : "spot" )),
			l->mColorDiffuse.r, l->mColorDiffuse.g, l->mColorDiffuse.b,
			l->mColorSpecular.r,l->mColorSpecular.g,l->mColorSpecular.b,
			l->mColorAmbient.r, l->mColorAmbient.g, l->mColorAmbient.b);

		if (l->mType != aiLightSource_DIRECTIONAL) {
			fprintf(out,
				"\t\t<Vector3 name=\"pos\"       > %0 8f %0 8f %0 8f </Vector3>\n"
				"\t\t<Float   name=\"atten_cst\" > %f </Float>\n"
				"\t\t<Float   name=\"atten_lin\" > %f </Float>\n"
				"\t\t<Float   name=\"atten_sqr\" > %f </Float>\n",
				l->mPosition.x,l->mPosition.y,l->mPosition.z,
				l->mAttenuationConstant,l->mAttenuationLinear,l->mAttenuationQuadratic);
		}

		if (l->mType != aiLightSource_POINT) {
			fprintf(out,
				"\t\t<Vector3 name=\"lookat\"    > %0 8f %0 8f %0 8f </Vector3>\n",
				l->mDirection.x,l->mDirection.y,l->mDirection.z);
		}

		if (l->mType == aiLightSource_SPOT) {
			fprintf(out,
				"\t\t<Float   name=\"cone_out\" > %f </Float>\n"
				"\t\t<Float   name=\"cone_inn\" > %f </Float>\n",
				l->mAngleOuterCone,l->mAngleInnerCone);
		}
		fprintf(out,"\t</Light>\n");
	}
#endif

	// write textures
	if (scene->mNumTextures) {
		fprintf(out,"<TextureList num=\"%i\">\n",scene->mNumTextures);
		for (unsigned int i = 0; i < scene->mNumTextures;++i) {
			aiTexture* tex  = scene->mTextures[i];
			bool compressed = (tex->mHeight == 0);

			// mesh header
			fprintf(out,"\t<Texture width=\"%i\" height=\"%i\" compressed=\"%s\"> \n",
				(compressed ? -1 : tex->mWidth),(compressed ? -1 : tex->mHeight),
				(compressed ? "true" : "false"));

			if (compressed) {
				fprintf(out,"\t\t<Data length=\"%i\"> \n",tex->mWidth);

				if (!shortened) {
					for (unsigned int n = 0; n < tex->mWidth;++n) {
						fprintf(out,"\t\t\t%2x",reinterpret_cast<uint8_t*>(tex->pcData)[n]);
						if (n && !(n % 50)) {
							fprintf(out,"\n");
						}
					}
				}
			}
			else if (!shortened){
				fprintf(out,"\t\t<Data length=\"%i\"> \n",tex->mWidth*tex->mHeight*4);

				// const unsigned int width = (unsigned int)log10((double)std::max(tex->mHeight,tex->mWidth))+1;
				for (unsigned int y = 0; y < tex->mHeight;++y) {
					for (unsigned int x = 0; x < tex->mWidth;++x) {
						aiTexel* tx = tex->pcData + y*tex->mWidth+x;
						unsigned int r = tx->r,g=tx->g,b=tx->b,a=tx->a;
						fprintf(out,"\t\t\t%2x %2x %2x %2x",r,g,b,a);

						// group by four for readibility
						if (0 == (x+y*tex->mWidth) % 4)
							fprintf(out,"\n");
					}
				}
			}
			fprintf(out,"\t\t</Data>\n\t</Texture>\n");
		}
		fprintf(out,"</TextureList>\n");
	}

	// write materials
	if (scene->mNumMaterials) {
		fprintf(out,"<MaterialList num=\"%i\">\n",scene->mNumMaterials);
		for (unsigned int i = 0; i< scene->mNumMaterials; ++i) {
			const aiMaterial* mat = scene->mMaterials[i];

			fprintf(out,"\t<Material>\n");
			fprintf(out,"\t\t<MatPropertyList  num=\"%i\">\n",mat->mNumProperties);
			for (unsigned int n = 0; n < mat->mNumProperties;++n) {

				const aiMaterialProperty* prop = mat->mProperties[n];
				const char* sz = "";
				if (prop->mType == aiPTI_Float) {
					sz = "float";
				}
				else if (prop->mType == aiPTI_Integer) {
					sz = "integer";
				}
				else if (prop->mType == aiPTI_String) {
					sz = "string";
				}
				else if (prop->mType == aiPTI_Buffer) {
					sz = "binary_buffer";
				}

				fprintf(out,"\t\t\t<MatProperty key=\"%s\" \n\t\t\ttype=\"%s\" tex_usage=\"%s\" tex_index=\"%i\"",
					prop->mKey.data, sz,
					::TextureTypeToString((aiTextureType)prop->mSemantic),prop->mIndex);

				if (prop->mType == aiPTI_Float) {
					fprintf(out," size=\"%i\">\n\t\t\t\t",
						static_cast<int>(prop->mDataLength/sizeof(float)));

					for (unsigned int p = 0; p < prop->mDataLength/sizeof(float);++p) {
						fprintf(out,"%f ",*((float*)(prop->mData+p*sizeof(float))));
					}
				}
				else if (prop->mType == aiPTI_Integer) {
					fprintf(out," size=\"%i\">\n\t\t\t\t",
						static_cast<int>(prop->mDataLength/sizeof(int)));

					for (unsigned int p = 0; p < prop->mDataLength/sizeof(int);++p) {
						fprintf(out,"%i ",*((int*)(prop->mData+p*sizeof(int))));
					}
				}
				else if (prop->mType == aiPTI_Buffer) {
					fprintf(out," size=\"%i\">\n\t\t\t\t",
						static_cast<int>(prop->mDataLength));

					for (unsigned int p = 0; p < prop->mDataLength;++p) {
						fprintf(out,"%2x ",prop->mData[p]);
						if (p && 0 == p%30) {
							fprintf(out,"\n\t\t\t\t");
						}
					}
				}
				else if (prop->mType == aiPTI_String) {
					fprintf(out,">\n\t\t\t\"%s\"",prop->mData+4 /* skip length */);
				}
				fprintf(out,"\n\t\t\t</MatProperty>\n");
			}
			fprintf(out,"\t\t</MatPropertyList>\n");
			fprintf(out,"\t</Material>\n");
		}
		fprintf(out,"</MaterialList>\n");
	}

	// write animations
	if (scene->mNumAnimations) {
		fprintf(out,"<AnimationList num=\"%i\">\n",scene->mNumAnimations);
		for (unsigned int i = 0; i < scene->mNumAnimations;++i) {
			aiAnimation* anim = scene->mAnimations[i];

			// anim header
			ConvertName(name,anim->mName);
			fprintf(out,"\t<Animation name=\"%s\" duration=\"%e\" tick_cnt=\"%e\">\n",
				name.data, anim->mDuration, anim->mTicksPerSecond);

			// write bone animation channels
			if (anim->mNumChannels) {
				fprintf(out,"\t\t<NodeAnimList num=\"%i\">\n",anim->mNumChannels);
				for (unsigned int n = 0; n < anim->mNumChannels;++n) {
					aiNodeAnim* nd = anim->mChannels[n];

					// node anim header
					ConvertName(name,nd->mNodeName);
					fprintf(out,"\t\t\t<NodeAnim node=\"%s\">\n",name.data);

					if (!shortened) {
						// write position keys
						if (nd->mNumPositionKeys) {
							fprintf(out,"\t\t\t\t<PositionKeyList num=\"%i\">\n",nd->mNumPositionKeys);
							for (unsigned int a = 0; a < nd->mNumPositionKeys;++a) {
								aiVectorKey* vc = nd->mPositionKeys+a;
								fprintf(out,"\t\t\t\t\t<PositionKey time=\"%e\">\n"
									"\t\t\t\t\t\t%0 8f %0 8f %0 8f\n\t\t\t\t\t</PositionKey>\n",
									vc->mTime,vc->mValue.x,vc->mValue.y,vc->mValue.z);
							}
							fprintf(out,"\t\t\t\t</PositionKeyList>\n");
						}

						// write scaling keys
						if (nd->mNumScalingKeys) {
							fprintf(out,"\t\t\t\t<ScalingKeyList num=\"%i\">\n",nd->mNumScalingKeys);
							for (unsigned int a = 0; a < nd->mNumScalingKeys;++a) {
								aiVectorKey* vc = nd->mScalingKeys+a;
								fprintf(out,"\t\t\t\t\t<ScalingKey time=\"%e\">\n"
									"\t\t\t\t\t\t%0 8f %0 8f %0 8f\n\t\t\t\t\t</ScalingKey>\n",
									vc->mTime,vc->mValue.x,vc->mValue.y,vc->mValue.z);
							}
							fprintf(out,"\t\t\t\t</ScalingKeyList>\n");
						}

						// write rotation keys
						if (nd->mNumRotationKeys) {
							fprintf(out,"\t\t\t\t<RotationKeyList num=\"%i\">\n",nd->mNumRotationKeys);
							for (unsigned int a = 0; a < nd->mNumRotationKeys;++a) {
								aiQuatKey* vc = nd->mRotationKeys+a;
								fprintf(out,"\t\t\t\t\t<RotationKey time=\"%e\">\n"
									"\t\t\t\t\t\t%0 8f %0 8f %0 8f %0 8f\n\t\t\t\t\t</RotationKey>\n",
									vc->mTime,vc->mValue.x,vc->mValue.y,vc->mValue.z,vc->mValue.w);
							}
							fprintf(out,"\t\t\t\t</RotationKeyList>\n");
						}
					}
					fprintf(out,"\t\t\t</NodeAnim>\n");
				}
				fprintf(out,"\t\t</NodeAnimList>\n");
			}
			fprintf(out,"\t</Animation>\n");
		}
		fprintf(out,"</AnimationList>\n");
	}

	// write meshes
	if (scene->mNumMeshes) {
		fprintf(out,"<MeshList num=\"%i\">\n",scene->mNumMeshes);
		for (unsigned int i = 0; i < scene->mNumMeshes;++i) {
			aiMesh* mesh = scene->mMeshes[i];
			// const unsigned int width = (unsigned int)log10((double)mesh->mNumVertices)+1;

			// mesh header
			fprintf(out,"\t<Mesh types=\"%s %s %s %s\" material_index=\"%i\">\n",
				(mesh->mPrimitiveTypes & aiPrimitiveType_POINT    ? "points"    : ""),
				(mesh->mPrimitiveTypes & aiPrimitiveType_LINE     ? "lines"     : ""),
				(mesh->mPrimitiveTypes & aiPrimitiveType_TRIANGLE ? "triangles" : ""),
				(mesh->mPrimitiveTypes & aiPrimitiveType_POLYGON  ? "polygons"  : ""),
				mesh->mMaterialIndex);

			// bones
			if (mesh->mNumBones) {
				fprintf(out,"\t\t<BoneList num=\"%i\">\n",mesh->mNumBones);

				for (unsigned int n = 0; n < mesh->mNumBones;++n) {
					aiBone* bone = mesh->mBones[n];

					ConvertName(name,bone->mName);
					// bone header
					fprintf(out,"\t\t\t<Bone name=\"%s\">\n"
						"\t\t\t\t<Matrix4> \n"
						"\t\t\t\t\t%0 6f %0 6f %0 6f %0 6f\n"
						"\t\t\t\t\t%0 6f %0 6f %0 6f %0 6f\n"
						"\t\t\t\t\t%0 6f %0 6f %0 6f %0 6f\n"
						"\t\t\t\t\t%0 6f %0 6f %0 6f %0 6f\n"
						"\t\t\t\t</Matrix4> \n",
						name.data,
						bone->mOffsetMatrix.a1,bone->mOffsetMatrix.a2,bone->mOffsetMatrix.a3,bone->mOffsetMatrix.a4,
						bone->mOffsetMatrix.b1,bone->mOffsetMatrix.b2,bone->mOffsetMatrix.b3,bone->mOffsetMatrix.b4,
						bone->mOffsetMatrix.c1,bone->mOffsetMatrix.c2,bone->mOffsetMatrix.c3,bone->mOffsetMatrix.c4,
						bone->mOffsetMatrix.d1,bone->mOffsetMatrix.d2,bone->mOffsetMatrix.d3,bone->mOffsetMatrix.d4);

					if (!shortened && bone->mNumWeights) {
						fprintf(out,"\t\t\t\t<WeightList num=\"%i\">\n",bone->mNumWeights);

						// bone weights
						for (unsigned int a = 0; a < bone->mNumWeights;++a) {
							aiVertexWeight* wght = bone->mWeights+a;

							fprintf(out,"\t\t\t\t\t<Weight index=\"%i\">\n\t\t\t\t\t\t%f\n\t\t\t\t\t</Weight>\n",
								wght->mVertexId,wght->mWeight);
						}
						fprintf(out,"\t\t\t\t</WeightList>\n");
					}
					fprintf(out,"\t\t\t</Bone>\n");
				}
				fprintf(out,"\t\t</BoneList>\n");
			}

			// faces
			if (!shortened && mesh->mNumFaces) {
				fprintf(out,"\t\t<FaceList num=\"%i\">\n",mesh->mNumFaces);
				for (unsigned int n = 0; n < mesh->mNumFaces; ++n) {
					aiFace& f = mesh->mFaces[n];
					fprintf(out,"\t\t\t<Face num=\"%i\">\n"
						"\t\t\t\t",f.mNumIndices);

					for (unsigned int j = 0; j < f.mNumIndices;++j)
						fprintf(out,"%i ",f.mIndices[j]);

					fprintf(out,"\n\t\t\t</Face>\n");
				}
				fprintf(out,"\t\t</FaceList>\n");
			}

			// vertex positions
			if (mesh->HasPositions()) {
				fprintf(out,"\t\t<Positions num=\"%i\" set=\"0\" num_components=\"3\"> \n",mesh->mNumVertices);
				if (!shortened) {
					for (unsigned int n = 0; n < mesh->mNumVertices; ++n) {
						fprintf(out,"\t\t%0 8f %0 8f %0 8f\n",
							mesh->mVertices[n].x,
							mesh->mVertices[n].y,
							mesh->mVertices[n].z);
					}
				}
				fprintf(out,"\t\t</Positions>\n");
			}

			// vertex normals
			if (mesh->HasNormals()) {
				fprintf(out,"\t\t<Normals num=\"%i\" set=\"0\" num_components=\"3\"> \n",mesh->mNumVertices);
				if (!shortened) {
					for (unsigned int n = 0; n < mesh->mNumVertices; ++n) {
						fprintf(out,"\t\t%0 8f %0 8f %0 8f\n",
							mesh->mNormals[n].x,
							mesh->mNormals[n].y,
							mesh->mNormals[n].z);
					}
				}
				else {
				}
				fprintf(out,"\t\t</Normals>\n");
			}

			// vertex tangents and bitangents
			if (mesh->HasTangentsAndBitangents()) {
				fprintf(out,"\t\t<Tangents num=\"%i\" set=\"0\" num_components=\"3\"> \n",mesh->mNumVertices);
				if (!shortened) {
					for (unsigned int n = 0; n < mesh->mNumVertices; ++n) {
						fprintf(out,"\t\t%0 8f %0 8f %0 8f\n",
							mesh->mTangents[n].x,
							mesh->mTangents[n].y,
							mesh->mTangents[n].z);
					}
				}
				fprintf(out,"\t\t</Tangents>\n");

				fprintf(out,"\t\t<Bitangents num=\"%i\" set=\"0\" num_components=\"3\"> \n",mesh->mNumVertices);
				if (!shortened) {
					for (unsigned int n = 0; n < mesh->mNumVertices; ++n) {
						fprintf(out,"\t\t%0 8f %0 8f %0 8f\n",
							mesh->mBitangents[n].x,
							mesh->mBitangents[n].y,
							mesh->mBitangents[n].z);
					}
				}
				fprintf(out,"\t\t</Bitangents>\n");
			}

			// texture coordinates
			for (unsigned int a = 0; a < AI_MAX_NUMBER_OF_TEXTURECOORDS; ++a) {
				if (!mesh->mTextureCoords[a])
					break;

				fprintf(out,"\t\t<TextureCoords num=\"%i\" set=\"%i\" num_components=\"%i\"> \n",mesh->mNumVertices,
					a,mesh->mNumUVComponents[a]);
				
				if (!shortened) {
					if (mesh->mNumUVComponents[a] == 3) {
						for (unsigned int n = 0; n < mesh->mNumVertices; ++n) {
							fprintf(out,"\t\t%0 8f %0 8f %0 8f\n",
								mesh->mTextureCoords[a][n].x,
								mesh->mTextureCoords[a][n].y,
								mesh->mTextureCoords[a][n].z);
						}
					}
					else {
						for (unsigned int n = 0; n < mesh->mNumVertices; ++n) {
							fprintf(out,"\t\t%0 8f %0 8f\n",
								mesh->mTextureCoords[a][n].x,
								mesh->mTextureCoords[a][n].y);
						}
					}
				}
				fprintf(out,"\t\t</TextureCoords>\n");
			}

			// vertex colors
			for (unsigned int a = 0; a < AI_MAX_NUMBER_OF_COLOR_SETS; ++a) {
				if (!mesh->mColors[a])
					break;
				fprintf(out,"\t\t<Colors num=\"%i\" set=\"%i\" num_components=\"4\"> \n",mesh->mNumVertices,a);
				if (!shortened) {
					for (unsigned int n = 0; n < mesh->mNumVertices; ++n) {
						fprintf(out,"\t\t%0 8f %0 8f %0 8f %0 8f\n",
							mesh->mColors[a][n].r,
							mesh->mColors[a][n].g,
							mesh->mColors[a][n].b,
							mesh->mColors[a][n].a);
					}
				}
				fprintf(out,"\t\t</Color>\n");
			}
			fprintf(out,"\t</Mesh>\n");
		}
		fprintf(out,"</MeshList>\n");
	}
	fprintf(out,"</Scene>\n</ASSIMP>");
}
示例#16
0
文件: GiST.cpp 项目: voidcycles/m3
void 
GiST::Split(GiSTnode **node, const GiSTentry& entry)
{
	int went_left=0, new_root=0;

	if((*node)->Path().IsRoot()) {
		new_root=1;
		(*node)->Path().MakeChild(store->Allocate());
	}

	GiSTnode *node2=(*node)->PickSplit();
	node2->Path().MakeSibling(store->Allocate());
	GiSTentry *e=(*node)->SearchPtr(entry.Ptr());

	if(e!=NULL) {
		went_left=1;
		delete e;
	}
	node2->SetSibling((*node)->Sibling());
	(*node)->SetSibling(node2->Path().Page());
	WriteNode(*node);
	WriteNode(node2);

	GiSTentry *e1=(*node)->Union();
	GiSTentry *e2=node2->Union();

	e1->SetPtr((*node)->Path().Page());
	e2->SetPtr(node2->Path().Page());
	// Create new root if root is being split
	if (new_root) {
		GiSTnode *root=NewNode(this);

		root->SetLevel((*node)->Level()+1);
		root->InsertBefore(*e1, 0);
		root->InsertBefore(*e2, 1);
		root->Path().MakeRoot();
		WriteNode(root);
		delete root;
	}
	else {
		// Insert entry for N' in parent
		GiSTpath parent_path=(*node)->Path();
		parent_path.MakeParent();
		GiSTnode *parent=ReadNode(parent_path);
		// Find the entry for N in parent
		GiSTentry *e=parent->SearchPtr((*node)->Path().Page());
		assert(e!=NULL);
		// Insert the new entry right after it
		int pos=e->Position();

		parent->DeleteEntry(pos);
		parent->InsertBefore(*e1, pos);
		parent->InsertBefore(*e2, pos+1);
		delete e;
		if(!parent->IsOverFull(*store)) WriteNode(parent);
		else {
			Split(&parent, went_left? *e1: *e2);
			GiSTpage page=(*node)->Path().Page();

			(*node)->Path()=parent->Path();
			(*node)->Path().MakeChild(page);
			page=node2->Path().Page();
			node2->Path()=(*node)->Path();
			node2->Path().MakeSibling(page);
		}
		delete parent;
	}
	if(!went_left) {
		delete *node;
		*node=node2;
	}
	else delete node2;
	delete e1;
	delete e2;
}
void WriteLevel(EDGELIST *tree, int currentLevel) {
	FILE *fp;
	POSITION currentEdge;
	char filename[80];
	EDGE theEdge;

	sprintf(filename, "visualization/m%s/m%s_%d_level_%d_vis.dot", kDBName, kDBName, getOption(), currentLevel);
	fp = fopen(filename, "w+");

	fprintf(fp, "/* Visualization of game tree of %s, variant %d*/\n", kGameName, getOption());
	fprintf(fp, "digraph g {\n");
	fprintf(fp, "\tlabel = \"%s, variant %d\"\n", kGameName, getOption());
	fprintf(fp, "\tlabelloc = \"top\"\n");
	fprintf(fp, "\tranksep = 1\n");
	fprintf(fp, "\tnode [fixedsize = \"true\", width = .75, height = .75]\n");
	//fprintf(fp, "\tmode = \"hier\"\n");
	//fprintf(fp, "\tmodel = \"circuit\"\n");

	/* Turn off edge drawing if gDrawEdges is FALSE */
	if(!gDrawEdges) {
		fprintf(fp, "\tsplines = \"\"\n");
	}

	fprintf(fp, "\tsubgraph cluster_%d {\n", currentLevel);
	fprintf(fp, "\t\tlabel = \"Level %d\"\n", currentLevel);
	fprintf(fp, "\t\tcolor = \"blue\"\n\n");

	/* Draw legend */
	fprintf(fp, "\t\tsubgraph cluster_toc {\n");
	fprintf(fp, "\t\t\trank = \"max\"\n");
	fprintf(fp, "\t\t\tlabel = \"Legend\"\n");
	fprintf(fp, "\t\t\tcolor = \"blue\"\n");

	/* Legend: Meaning of shapes */
	fprintf(fp, "\t\t\tsubgraph cluster_shape {\n");
	fprintf(fp, "\t\t\t\trank = \"same\"\n");
	fprintf(fp, "\t\t\t\tlabel = \"Position Shapes\"\n");
	fprintf(fp, "\t\t\t\tdefault [shape = \"%s\", label = \"Non-draw\"]\n", DEFAULT_SHAPE);
	fprintf(fp, "\t\t\t\tdraw [shape = \"%s\", label = \"Draw\"]\n", DRAW_SHAPE);
	fprintf(fp, "\t\t\t\tfringe [shape = \"%s\", label = \"Fringe\"]\n", FRINGE_SHAPE);
	fprintf(fp, "\t\t\t}\n");

	/* Legend: Meaning of colors */
	fprintf(fp, "\t\t\tsubgraph cluster_color {\n");
	fprintf(fp, "\t\t\t\trank = \"same\"\n");
	fprintf(fp, "\t\t\t\tlabel = \"Position Colors\"\n");
	fprintf(fp, "\t\t\t\twin [label = \"Win\", shape = \"%s\", style = \"filled\", color = \"%s\"]\n", DEFAULT_SHAPE, WIN_COLOR);
	fprintf(fp, "\t\t\t\ttie [label = \"Tie\", shape = \"%s\", style = \"filled\", color = \"%s\"]\n", DEFAULT_SHAPE, TIE_COLOR);
	fprintf(fp, "\t\t\t\tlose [label = \"Lose\", shape = \"%s\", style = \"filled\", color = \"%s\"]\n", DEFAULT_SHAPE, LOSE_COLOR);
	fprintf(fp, "\t\t\t\tdraw2 [label = \"Draw\", shape = \"%s\", style = \"filled\", color = \"%s\"]\n", DEFAULT_SHAPE, DRAW_COLOR);
	fprintf(fp, "\t\t\t}\n");
	fprintf(fp, "\t\t}\n");

	for(currentEdge = 0; currentEdge < (tree->nextEdgeInLevel)[currentLevel]; currentEdge++) {
		theEdge = (tree->edges)[currentLevel][currentEdge];
		WriteNode(fp, theEdge.Parent, currentLevel, tree);
		WriteNode(fp, theEdge.Child, currentLevel, tree);

		fprintf(fp, "\t\t%llu -> %llu [color = \"%s\"]\n", theEdge.Parent, theEdge.Child, MoveColor(theEdge));
	}

	if(gRemotenessOrder) {
		WriteRanks(fp, tree);
		PrepareRankList(tree);
	}

	fprintf(fp, "\t}\n");
	fprintf(fp, "}\n");
	fclose(fp);
	UnMarkAllAsVisited();
}
示例#18
0
// load this M-tree with n data using the BulkLoad algorithm [CP98]
// data is an array of n entries
// padFactor is the maximum node utilization (use 1)
// name is the name of the tree
void
MT::BulkLoad (MTentry **data, int n, double padFactor, const char *name)
{
	int size = 0;
	if (EntrySize()) {
		size = n * (sizeof(GiSTpage) + EntrySize());  // (only valid if we've fixed size entries)
	} else {
		for (int i=0; i<n; i++) {
			size += sizeof(GiSTlte) + sizeof(GiSTpage) + data[i]->CompressedLength();
		}
	}
	int totSize = size + GIST_PAGE_HEADER_SIZE + sizeof(GiSTlte);

	if (totSize > Store()->PageSize()) {  // we need to split the entries into several sub-trees
		int numEntries = (int)(Store()->PageSize()*padFactor*n) / totSize;
		int s = (int) MAX (MIN (numEntries, ceil(((float)n)/numEntries)), numEntries*MIN_UTIL);  // initial number of samples
		int nSamples, *samples = new int[s], *sizes = NULL, *ns = NULL, iter = 0, MAXITER = s * s;
		GiSTlist<double *> *distm = (GiSTlist<double *> *) calloc (s, sizeof(GiSTlist<double *>));  // relative distances between samples
		int MINSIZE = (int) (Store()->PageSize()*MIN_UTIL), addEntrySize = EntrySize() ? sizeof(GiSTpage) : sizeof(GiSTlte)+sizeof(GiSTpage);
		GiSTlist<int> *lists = NULL;  // set for each sample set
		GiSTlist<double> *dists = NULL;  // set for distance between each sample and its members
		BOOL *bSampled = new BOOL[n];  // is this entry in the samples set?

		// sampling phase
		do {
			iter++;
			if (iter > 1) {  // this is a new sampling phase
				while (!lists[0].IsEmpty()) {
					lists[0].RemoveFront ();
					dists[0].RemoveFront ();
				}
				delete []lists;
				delete []dists;
				delete []sizes;
				delete []ns;
				while (!distm[0].IsEmpty()) {
					delete []distm[0].RemoveFront();  // empty the distance list
				}
				for (int i=1; i<s; i++) {
					distm[i].front = distm[i].rear = NULL;
				}
			}
			if (iter >= MAXITER) {
				cout << "Too many loops in BulkLoad!"<<endl<<"Please select a lower minimum node utilization or a bigger node size."<<endl;
				exit(1);
			}

			for (int i=0; i<n; i++) {
				bSampled[i] = FALSE;
			}
			nSamples = 0;
			// pick s samples to create parents
			while (nSamples < s) {
				int i;
				do {
					i = PickRandom (0, n);
				} while (bSampled[i]);
				bSampled[i] = TRUE;
				samples[nSamples++] = i;
			}

			lists = new GiSTlist<int>[s];
			dists = new GiSTlist<double>[s];
			sizes = new int[s];
			ns = new int[s];
			for (int i=0; i<s; i++) {
				sizes[i] = GIST_PAGE_HEADER_SIZE + sizeof(GiSTlte);
				ns[i] = 1;
				distm[i].Prepend (new double[s]);
			}

			// compute the relative distances between samples
			for (int i=0; i<s; i++) {
				for (int j=0; j<i; j++) {
					distm[j].front->entry[i] = distm[i].front->entry[j] = data[samples[j]]->object().distance(data[samples[i]]->object());
				}
				distm[i].front->entry[i] = 0;
			}

			// assign each entry to its nearest parent
			for (int i=0; i<n; i++) {
				if (bSampled[i]) {
					int j = 0;
					for (; samples[j]!=i; j++);  // find this entry in the samples set and return position in it
					lists[j].Prepend (i);  // insert the entry in the right sample
					dists[j].Prepend (0);  // distance between sample and data[i]
					sizes[j] += addEntrySize + data[i]->CompressedLength();
				} else {  // here we optimize the distance computations (like we do in the insert algorithm)
					double *dist = new double[s];  // distance between this non-sample and samples
					dist[0] = data[samples[0]]->object().distance(data[i]->object());
					int minIndex = 0;
					for (int j=1; j<s; j++) {  // seek the nearest sample
						dist[j] = -MaxDist();
						if (fabs (data[samples[j]]->Key()->distance - data[i]->Key()->distance) >= dist[minIndex]) {  // pruning
							continue;
						}
						BOOL flag = TRUE;
						for (int k=0; k<j && flag; k++) {  // pruning (other samples)
							if (dist[k] < 0) {
								continue;
							} else {
								flag = fabs (dist[k] - distm[j].front->entry[k]) < dist[minIndex];
							}
						}
						if (!flag) {
							continue;
						}
						dist[j] = data[samples[j]]->object().distance(data[i]->object());  // have to compute this distance
						if (dist[j] < dist[minIndex]) {
							minIndex = j;
						}
					}
					lists[minIndex].Append (i);  // insert the entry in the right sample
					dists[minIndex].Append (dist[minIndex]);  // distance between sample and data[i]
					sizes[minIndex] += addEntrySize + data[i]->CompressedLength();
					ns[minIndex]++;
					sizes[minIndex] >= MINSIZE ? delete []dist : distm[minIndex].Append (dist);  // correspond with lists
				}
			}

			// redistribute underfilled parents
			int i;
			while (sizes[i = FindMin (sizes, nSamples)] < MINSIZE) {
				GiSTlist<int> list = lists[i];  // each sample set
				while (!dists[i].IsEmpty()) {  // clear distance between each sample and its members
					dists[i].RemoveFront ();
				}

				// substitute this set with last set
				for (int j=0; j<nSamples; j++) {
					for (GiSTlistnode<double *> *node=distm[j].front; node; node=node->next) {
						node->entry[i] = node->entry[nSamples-1];
					}
				}
				GiSTlist<double *> dlist = distm[i];  // relative distances between sample[i] and other samples, reposition by myself

				distm[i] = distm[nSamples-1];
				lists[i] = lists[nSamples-1];
				dists[i] = dists[nSamples-1];
				samples[i] = samples[nSamples-1];
				sizes[i] = sizes[nSamples-1];
				ns[i] = ns[nSamples-1];
				nSamples--;
				while (!list.IsEmpty()) {  // assign each entry to its nearest parent
					double *dist = dlist.RemoveFront ();  // relative distances between sample[i] (old) and other samples (old)
					int minIndex = -1;
					for (int j=0; j<nSamples && minIndex<0; j++) {  // search for a computed distance
						if (dist[j] > 0) {
							minIndex = j;
						}
					}
					int k = list.RemoveFront ();
					if (minIndex < 0) {  // no distance was computed (i.e. all distances were pruned)
						dist[0] = data[samples[0]]->object().distance(data[k]->object());
						minIndex = 0;
					}
					for (int j=0; j<nSamples; j++) {
						if (j == minIndex) {
							continue;
						}
						if (dist[j] < 0) {  // distance wasn't computed
							if (fabs (data[samples[j]]->Key()->distance - data[k]->Key()->distance) >= dist[minIndex]) {
								continue;  // pruning
							}
							BOOL flag = TRUE;
							for (int i=0; i<j && flag; i++) { // pruning (other samples)
								if (dist[i] < 0) {
									continue;
								} else {
									flag = fabs (dist[i] - distm[j].front->entry[i]) < dist[minIndex];
								}
							}
							if (!flag) {
								continue;
							}
							dist[j] = data[samples[j]]->object().distance(data[k]->object());  // have to compute this distance
						}
						if (dist[j] < dist[minIndex]) {
							minIndex = j;
						}
					}
					lists[minIndex].Append (k);
					dists[minIndex].Append (dist[minIndex]);
					sizes[minIndex] += addEntrySize + data[k]->CompressedLength();
					ns[minIndex]++;
					sizes[minIndex] >= MINSIZE ? delete []dist : distm[minIndex].Append (dist);  // correspond with lists
				}
				assert (dlist.IsEmpty());  // so is the list
			}
		} while (nSamples == 1);  // if there's only one child, repeat the sampling phase
		MTentry ***array = new MTentry **[nSamples];  // array of the entries for each sub-tree
		for (int i=0; i<nSamples; i++) {  // convert the lists into arrays
			array[i] = new MTentry *[ns[i]];
			for (int j=0; j<ns[i]; j++) {
				array[i][j] = (MTentry *) data[lists[i].RemoveFront ()]->Copy();
				array[i][j]->Key()->distance = dists[i].RemoveFront ();
			}
			assert (lists[i].IsEmpty());
			assert (dists[i].IsEmpty());
		}
		delete []lists;
		delete []dists;
		delete []sizes;
		delete []bSampled;
		for (int i=0; i<nSamples; i++) {
			while (!distm[i].IsEmpty()) {
				delete [](distm[i].RemoveFront());
			}
		}
		free (distm);

		// build an M-tree under each parent
		int nInit = nSamples;
		MT *subtree = new MT;
		GiSTlist<char *> subtreeNames;  // list of the subtrees names
		GiSTlist<MTentry *> topEntries;  // list of the parent entries of each subtree
		int nCreated = 0, minHeight = MAXINT;
		char newName[50];
		for (int i=0; i<nInit; i++) {
			sprintf (newName, "%s.%i", name, ++nCreated);
			unlink (newName);
			subtree->Create(newName);  // create the new subtree
			subtree->BulkLoad(array[i], ns[i], padFactor, newName);  // build the subtree

			GiSTpath path;
			path.MakeRoot ();
			MTnode *subtreeRoot = (MTnode *) subtree->ReadNode(path);
			if (subtreeRoot->IsUnderFull(*Store())) {  // if the subtree root node is underfilled, we have to split the tree
				GiSTlist<MTentry *> *parentEntries = new GiSTlist<MTentry *>;
				GiSTlist<char *> *newTreeNames = subtree->SplitTree(&nCreated, subtree->TreeHeight()-1, parentEntries, name);  // split the tree
				nSamples--;
				while (!newTreeNames->IsEmpty()) {  // insert all the new trees in the subtrees list
					subtreeNames.Append (newTreeNames->RemoveFront());
					MTentry *entry = parentEntries->RemoveFront();
					for (int j=0; j<n; j++) {
						if (data[j]->object() == entry->object()) {  // append the parent entry to the list
							topEntries.Append (data[j]);
							break;
						}
					}
					delete entry;
					nSamples++;
				}
				delete newTreeNames;
				delete parentEntries;
				minHeight = MIN (minHeight, subtree->TreeHeight()-1);
			} else {
				subtreeNames.Append (strdup(newName));
				topEntries.Append (data[samples[i]]);
				minHeight = MIN (minHeight, subtree->TreeHeight());
			}
			delete subtreeRoot;
			subtree->Close();
			delete subtree->Store();  // it was created in subtree->Create()
		}
		delete []samples;
		for (int i=0; i<nInit; i++)  {
			for (int j=0; j<ns[i]; j++) {
				delete array[i][j];
			}
			delete []array[i];
		}
		delete []array;
		delete []ns;

		// fix the subtree height
		GiSTlist<char *> subtreeNames2;  // list of the subtrees names
		GiSTlist<MTentry *> topEntries2;  // list of the parent entries of each subtree
		while (!topEntries.IsEmpty()) {  // insert the trees in the list (splitting trees if necessary)
			MTentry *parentEntry = topEntries.RemoveFront ();
			char *tmp = subtreeNames.RemoveFront ();
			strcpy (newName, tmp);
			delete []tmp;
			subtree->Open(newName);
			if (subtree->TreeHeight() > minHeight) {  // we have to split the tree to reduce its height
				nSamples--;
				GiSTlist<MTentry *> *parentEntries = new GiSTlist<MTentry *>;
				GiSTlist<char *> *newTreeNames = subtree->SplitTree(&nCreated, minHeight, parentEntries, name);  // split the tree
				while (!newTreeNames->IsEmpty()) {  // insert all the new trees in the subtrees list
					subtreeNames2.Append (newTreeNames->RemoveFront());
					MTentry *entry = parentEntries->RemoveFront();
					for (int j=0; j<n; j++) {
						if (data[j]->object() == entry->object()) {  // append the parent entry to the parents list
							topEntries2.Append (data[j]);
							break;;
						}
					}
					delete entry;
					nSamples++;
				}
				delete newTreeNames;
				delete parentEntries;
			} else {  // simply insert the tree and its parent entry to the lists
				subtreeNames2.Append (strdup(newName));
				topEntries2.Append (parentEntry);
			}
			subtree->Close();
			delete subtree->Store();  // it was created in tree->Open()
		}

		// build the super tree upon the parents
		MTentry **topEntrArr = new MTentry *[nSamples];  // array of the parent entries for each subtree
		char **subNameArr = new char *[nSamples];  // array of the subtrees names
		for (int i=0; i<nSamples; i++) {  // convert the lists into arrays
			topEntrArr[i] = topEntries2.RemoveFront ();
			subNameArr[i] = subtreeNames2.RemoveFront ();
		}
		assert (topEntries2.IsEmpty());
		assert (subtreeNames2.IsEmpty());
		sprintf (newName, "%s.0", name);
		BulkLoad (topEntrArr, nSamples, padFactor, newName);
		// attach each subtree to the leaves of the super tree
		GiSTpath path;
		path.MakeRoot ();
		MTnode *node = (MTnode *) ReadNode (path);
		GiSTlist<MTnode *> *oldList = new GiSTlist<MTnode *>;  // upper level nodes
		oldList->Append(node);
		int level = node->Level();
		while (level > 0) {  // build the leaves list for super tree
			GiSTlist<MTnode *> *newList = new GiSTlist<MTnode *>;  // lower level nodes
			while (!oldList->IsEmpty()) {
				node = oldList->RemoveFront();
				path = node->Path();
				node->SetLevel(node->Level() + minHeight);  // update level of the upper nodes of the super tree
				WriteNode (node);
				for (int i=0; i<node->NumEntries(); i++) {
					MTentry *entry = (MTentry *) (*node)[i].Ptr();
					path.MakeChild (entry->Ptr());
					newList->Append((MTnode *)ReadNode(path));
					path.MakeParent ();
				}
				delete node;
			}
			delete oldList;
			oldList = newList;
			level--;
		}
		while (!oldList->IsEmpty()) {  // attach each subtree to its leaf
			node = oldList->RemoveFront();  // retrieve next leaf (root of subtree)
			node->SetLevel(minHeight);  // update level of the root of the subtree
			path = node->Path();
			for (int i=0; i<node->NumEntries(); i++) {
				MTentry *entry = (MTentry *) (*node)[i].Ptr();
				path.MakeChild(Store()->Allocate());
				MTnode *newNode = (MTnode *) CreateNode ();
				newNode->Path() = path;
				entry->SetPtr(path.Page());
				path.MakeParent ();
				int j = 0;
				for (; entry->object() != topEntrArr[j]->object(); j++);  // search the position to append
				subtree->Open(subNameArr[j]);
				GiSTpath rootPath;
				rootPath.MakeRoot ();
				Append (newNode, (MTnode *)subtree->ReadNode(rootPath));  // append this subtree to the super tree
				subtree->Close();
				delete subtree->Store();  // it was created in tree->Open()
				delete newNode;
			}
			WriteNode (node);
			delete node;
		}
		subtree->Open(subNameArr[0]);  // in order to destroy the object tree
		delete subtree;
		for (int i=0; i<nSamples; i++) {
			delete []subNameArr[i];
		}
		delete []subNameArr;
		delete []topEntrArr;

		// update radii of the upper nodes of the result M-tree
		path.MakeRoot ();
		node = (MTnode *) ReadNode (path);
		oldList->Append(node);
		level = node->Level();
		while (level >= minHeight) {  // build the list of the nodes which radii should be recomputed
			GiSTlist<MTnode *> *newList = new GiSTlist<MTnode *>;
			while (!oldList->IsEmpty()) {
				node = oldList->RemoveFront();
				path = node->Path();
				for (int i=0; i<node->NumEntries(); i++) {
					path.MakeChild ((*node)[i].Ptr()->Ptr());
					newList->Append((MTnode *)ReadNode(path));
					path.MakeParent ();
				}
				delete node;
			}
			delete oldList;
			oldList = newList;
			level--;
		}
		while (!oldList->IsEmpty()) {  // adjust the radii of the nodes
			MTnode *node = oldList->RemoveFront();
			AdjKeys (node);
			delete node;
		}
		delete oldList;
		for (int i=0; i<=nCreated; i++) {  // delete all temporary subtrees
			sprintf (newName, "%s.%i", name, i);
			unlink (newName);
		}
	} else {  // we can insert all the entries in a single node
		GiSTpath path;
		path.MakeRoot ();
		GiSTnode *node = ReadNode (path);
		for (int i=0; i<n; i++) {
			node->Insert(*(data[i]));
		}
		assert (!node->IsOverFull(*Store()));
		WriteNode (node);
		delete node;
	}
}
t_rc INXM_IndexHandle::InsertIntoParent(int rootID, STORM_PageHandle leftPage, INXM_Node &keyNode, STORM_PageHandle rightPage) {
	t_rc rc;
	INXM_InitPageHeader leftInitPageHeader;
	INXM_NodePageHeader leftNodePageHeader;
	LoadNodeHeaders(leftPage, leftInitPageHeader, leftNodePageHeader);
	
	/* Case: new root. */
	if (leftNodePageHeader.parent == 0) {
		int rightPageID;
		rc = rightPage.GetPageID(rightPageID);
		if (rc != OK) { return rc; }
		
		STORM_PageHandle newRootPageHandle;
		CreateNodePage(newRootPageHandle, this->inxmFileHeader.treeRoot, 0, rightPageID, 0, 0);
		
		int leftPageID;
		rc = leftPage.GetPageID(leftPageID);
		if (rc != OK) { return rc; }
		
		rc = WriteNode(newRootPageHandle, keyNode.key, leftPageID, 0);
		if (rc != OK) { return rc; }
		
		/* Update inxm file header. */
		memcpy(this->pData_FileHeader, &this->inxmFileHeader, INXM_FILEHEADER_SIZE);
		
		rc = this->sfh.FlushPage(this->pageNum_FileHeader);
		if (rc != OK) { return rc; }
		
		/* Write all. */
		rc = this->sfh.FlushAllPages();
		if (rc != OK) { return rc; }
		
		return(OK);
	}
		
	/* Case: leaf or node. (Remainder of
	 * function body.)  
	 */
	
	/* Find the parent's node index to the left 
	 * page.
	 */
	
	int leftPageID;
	rc = leftPage.GetPageID(leftPageID);
	if (rc != OK) { return rc; }
	
	int rightPageID;
	rc = rightPage.GetPageID(rightPageID);
	if (rc != OK) { return rc; }
	
	int left_index = 0;
	INXM_Node node;
	INXM_InitPageHeader parentInitPageHeader;
	INXM_NodePageHeader parentNodePageHeader;
	LoadNodeHeaders(leftNodePageHeader.parent, parentInitPageHeader, parentNodePageHeader);
	
	while (left_index < parentInitPageHeader.nItems) {
		ReadNode(leftNodePageHeader.parent, left_index, node);
		if (node.left == leftPageID) {
			break;
		}
		left_index++;
	}
	
	/* Simple case: the new key fits into the page. */
	STORM_PageHandle parentPageHandle;
	
	rc = this->sfh.GetPage(leftNodePageHeader.parent, parentPageHandle);
	if (rc != OK) { return rc; }
	
	if (LeafHasRoom(parentPageHandle)) {
		return InsertIntoNoLeaf(parentPageHandle, left_index, keyNode.key, rightPageID);
	}
	
	/* Harder case:  split a not leaf page, in order 
	 * to preserve the B+ tree properties.
	 */
	
//	return insert_into_node_after_splitting(root, parent, left_index, key, right);
	
	return(OK);
}
示例#20
0
	void DirectoryWriter::RecursiveList(string szPath, bool bRecursive)
	{
		DirectoryReader* reader = new DirectoryReader();
		DIR* pDir = NULL;

		pDir = reader->open(szPath, pDir);
		
		struct dirent* pEnt = NULL;

		int count = 0;
		while (pEnt = readdir(pDir))
		{
			if (strcmp(pEnt->d_name, ".") == 0 || strcmp(pEnt->d_name, "..") == 0)
				continue;

			string szCurrent(szPath);
			szCurrent.append("/");
			szCurrent.append(pEnt->d_name);
			szCurrent = ConvertPath(szCurrent);
			if (reader->isDir(szCurrent))
			{
				if (bRecursive)
				{
					// not sure...
					//delete reader;
					RecursiveList(ConvertPath(szCurrent), true);
				}
			}
			if (reader->isFile(szCurrent))
			{
				vector<string> segments = vector<string>();
				string currentPath = ConvertPath(szCurrent);
				StrSplit(currentPath, segments);

				string path = "";
				vector<string>temp = segments;
				for (size_t i = 0; i < temp.size(); i++)
				{
					if (strcmp(temp[i].c_str(),"mapje")==0)
					{
						break;
					}
					else
					{
						segments.erase(segments.begin());
					}
				}

				for (size_t i = 0; i < segments.size(); i++)
				{
					path.append(segments[i]);
					if (i!=segments.size()-1)
					{
						path.append("/");
					}
				}

				time_t iLastModified = reader->getLastModifiedTime(szCurrent);
				WriteNode(pEnt->d_name, path, to_string(iLastModified));
			}
			count++;
		}
		
		closedir(pDir);
		delete reader;
	}
示例#21
0
int VocabTreeLeaf::Write(FILE *f, int bf, int dim) const {
    return WriteNode(f, bf, dim);
}
t_rc INXM_IndexHandle::InsertIntoLeafAfterSplitting(int rootID, STORM_PageHandle leafPageHandle, void *key, const REM_RecordID &rid) {
	t_rc rc;
	STORM_PageHandle newLeafPageHandle;
	int newLeafPageID;
	rc = CreateNodePage(newLeafPageHandle, newLeafPageID, 0, 0, 0, true);
	if (rc != OK) { return rc; }
	
	/* Read leaf page headers. */
	INXM_InitPageHeader leafPageHeader;
	rc = LoadInitHeaders(leafPageHandle, leafPageHeader);
	if (rc != OK) { return rc; }
	
	int insertPoint = 0;
	INXM_Node node;
	ReadNode(leafPageHandle, insertPoint, node);
	while (insertPoint < leafPageHeader.nItems  && KeyCmp(node.key, key) < 0) {
		ReadNode(leafPageHandle, insertPoint, node);
		insertPoint++;
	}
	
	INXM_Node **temp_nodes = (INXM_Node **)malloc(INXM_NODE_SIZE*leafPageHeader.nItems);
	
	int i,j;
	for (i=0, j=0; i < leafPageHeader.nItems; i++, j++) {
		if (j == insertPoint) j++;
		ReadNode(leafPageHandle, i, *(temp_nodes[j]));
	}
	
	/* Write new data to last page. */
	int newDataSlot;
	STORM_PageHandle lastDataPageHandle;
	rc = this->sfh.GetPage(this->inxmFileHeader.lastDataPage, lastDataPageHandle);
	if (rc != OK) { return rc; }
	
	rc = WriteData(lastDataPageHandle, rid, newDataSlot);
	if (rc != OK) { return rc; }
	
	/* Place new node to temp array. */
	INXM_Node *newNode = new INXM_Node();
	newNode->key = key;
	newNode->left = this->inxmFileHeader.lastDataPage;
	newNode->slot = newDataSlot;
	temp_nodes[insertPoint] = newNode;
	
	/* Reset leaf's nItems */
	char *tmpData;
	leafPageHandle.GetDataPtr(&tmpData);
	leafPageHeader.nItems = 0;
	memcpy(tmpData, &leafPageHeader, INXM_INITPAGEHEADER_SIZE);
	
	int maxNodeRoom = (PAGE_DATA_SIZE-INXM_INITPAGEHEADER_SIZE-INXM_NODEPAGEHEADER_SIZE)/(INXM_NODE_SIZE+this->inxmFileHeader.attrLength);
	int split = Cut(maxNodeRoom);
	
	/* Write new data. */
	for (i = 0; i < split; i++) {
		WriteNode(leafPageHandle, i, temp_nodes[i]->key, temp_nodes[i]->left, temp_nodes[i]->slot);
	}
	
	for (i = split, j = 0; i < maxNodeRoom; i++, j++) {
		WriteNode(newLeafPageHandle, j, temp_nodes[i]->key, temp_nodes[i]->left, temp_nodes[i]->slot);
	}

	free(temp_nodes); // This is not enough!
	
	INXM_NodePageHeader leafNodePageHeader;
	LoadNodeHeaders(leafPageHandle, leafPageHeader, leafNodePageHeader);

	INXM_NodePageHeader newLeafNodePageHeader;
	INXM_InitPageHeader newLeafPageHeader;
	rc = LoadNodeHeaders(newLeafPageHandle, newLeafPageHeader, newLeafNodePageHeader);
	if (rc != OK) { return rc; }
	
	int leafPageID;
	rc = leafPageHandle.GetPageID(leafPageID);
	if (rc != OK) { return rc; }
	
	newLeafNodePageHeader.next = leafNodePageHeader.next;
	newLeafNodePageHeader.previous = leafPageID;
	leafNodePageHeader.next = newLeafPageID;
	
	if (newLeafNodePageHeader.next != 0) {
		STORM_PageHandle nextLeafPageHandle;
		rc = this->sfh.GetPage(newLeafNodePageHeader.next, nextLeafPageHandle);
		if (rc != OK) { return rc; }
		
		INXM_InitPageHeader nextInitPageHeader;
		INXM_NodePageHeader nextNodePageHeader;
		LoadNodeHeaders(nextLeafPageHandle, nextInitPageHeader, nextNodePageHeader);
		
		nextNodePageHeader.previous = newLeafPageID;
		
		UpdateNodeHeaders(nextLeafPageHandle, nextInitPageHeader, nextNodePageHeader);
	}
	
	rc = UpdateNodeHeaders(leafPageHandle, leafPageHeader, leafNodePageHeader);
	if (rc != OK) { return rc; }
	rc = UpdateNodeHeaders(newLeafPageHandle, newLeafPageHeader, newLeafNodePageHeader);
	if (rc != OK) { return rc; }
	
	INXM_Node keyNode;
	rc = ReadNode(newLeafPageHandle, 0, keyNode);
	if (rc != OK) { return rc; }
	
	rc = InsertIntoParent(this->inxmFileHeader.treeRoot, leafPageHandle, keyNode, newLeafPageHandle);
	if (rc != OK) { return rc; }
	
	return(OK);
}
template<> int GATreeGenome<int>::write(ostream & os) const {
	os << "      node     parent      child       next       prev\n";
	WriteNode(os, (GANode<int> *) rt);
	return os.fail() ? 1 : 0;
}
示例#24
0
// -----------------------------------------------------------------------------------
// Write a text model dump
void WriteDump(const aiScene* scene, FILE* out, const char* src, const char* cmd, bool shortened)
{
	time_t tt = ::time(NULL);
	tm* p     = ::gmtime(&tt);

	aiString name;

	// write header
	::fprintf(out,
		"<?xml version=\"1.0\" encoding=\"utf-8\"?>\n"
		"<ASSIMP >\n\n"

		"<!-- XML Model dump produced by assimp dump\n"
		"  Library version: %i.%i.%i\n"
		"  Source: %s\n"
		"  Command line: %s\n"
		"  %s\n"
		"-->"
		" \n\n"
		"<Scene NumberOfMeshes=\"%i\" NumberOfMaterials=\"%i\" NumberOfTextures=\"%i\" NumberOfCameras=\"%i\" NumberOfLights=\"%i\" NumberOfAnimations=\"%i\">\n",
		
		aiGetVersionMajor(),aiGetVersionMinor(),aiGetVersionRevision(),src,cmd,::asctime(p),
		scene->mNumMeshes, scene->mNumMaterials,scene->mNumTextures,
		scene->mNumCameras,scene->mNumLights,scene->mNumAnimations);

	// write the node graph
	WriteNode(scene->mRootNode, out, 1);

		// write cameras
	for (unsigned int i = 0; i < scene->mNumCameras;++i) {
		aiCamera* cam  = scene->mCameras[i];
		ConvertName(name,cam->mName);

		// camera header
		::fprintf(out,"\t<Camera parent=\"%s\">\n"
			"\t\t<Vector3 name=\"up\"        > %0 8f %0 8f %0 8f </Vector3>\n"
			"\t\t<Vector3 name=\"lookat\"    > %0 8f %0 8f %0 8f </Vector3>\n"
			"\t\t<Vector3 name=\"pos\"       > %0 8f %0 8f %0 8f </Vector3>\n"
			"\t\t<Float   name=\"fov\"       > %f </Float>\n"
			"\t\t<Float   name=\"aspect\"    > %f </Float>\n"
			"\t\t<Float   name=\"near_clip\" > %f </Float>\n"
			"\t\t<Float   name=\"far_clip\"  > %f </Float>\n"
			"\t</Camera>\n",
			name.data,
			cam->mUp.x,cam->mUp.y,cam->mUp.z,
			cam->mLookAt.x,cam->mLookAt.y,cam->mLookAt.z,
			cam->mPosition.x,cam->mPosition.y,cam->mPosition.z,
			cam->mHorizontalFOV,cam->mAspect,cam->mClipPlaneNear,cam->mClipPlaneFar,i);
	}

	// write lights
	for (unsigned int i = 0; i < scene->mNumLights;++i) {
		aiLight* l  = scene->mLights[i];
		ConvertName(name,l->mName);

		// light header
		::fprintf(out,"\t<Light parent=\"%s\"> type=\"%s\"\n"
			"\t\t<Vector3 name=\"diffuse\"   > %0 8f %0 8f %0 8f </Vector3>\n"
			"\t\t<Vector3 name=\"specular\"  > %0 8f %0 8f %0 8f </Vector3>\n"
			"\t\t<Vector3 name=\"ambient\"   > %0 8f %0 8f %0 8f </Vector3>\n",
			name.data,
			(l->mType == aiLightSource_DIRECTIONAL ? "directional" :
			(l->mType == aiLightSource_POINT ? "point" : "spot" )),
			l->mColorDiffuse.r, l->mColorDiffuse.g, l->mColorDiffuse.b,
			l->mColorSpecular.r,l->mColorSpecular.g,l->mColorSpecular.b,
			l->mColorAmbient.r, l->mColorAmbient.g, l->mColorAmbient.b);

		if (l->mType != aiLightSource_DIRECTIONAL) {
			::fprintf(out,
				"\t\t<Vector3 name=\"pos\"       > %0 8f %0 8f %0 8f </Vector3>\n"
				"\t\t<Float   name=\"atten_cst\" > %f </Float>\n"
				"\t\t<Float   name=\"atten_lin\" > %f </Float>\n"
				"\t\t<Float   name=\"atten_sqr\" > %f </Float>\n",
				l->mPosition.x,l->mPosition.y,l->mPosition.z,
				l->mAttenuationConstant,l->mAttenuationLinear,l->mAttenuationQuadratic);
		}

		if (l->mType != aiLightSource_POINT) {
			::fprintf(out,
				"\t\t<Vector3 name=\"lookat\"    > %0 8f %0 8f %0 8f </Vector3>\n",
				l->mDirection.x,l->mDirection.y,l->mDirection.z);
		}

		if (l->mType == aiLightSource_SPOT) {
			::fprintf(out,
				"\t\t<Float   name=\"cone_out\" > %f </Float>\n"
				"\t\t<Float   name=\"cone_inn\" > %f </Float>\n",
				l->mAngleOuterCone,l->mAngleInnerCone);
		}
		::fprintf(out,"\t</Light>\n");
	}

	// write textures
	for (unsigned int i = 0; i < scene->mNumTextures;++i) {
		aiTexture* tex  = scene->mTextures[i];
		bool compressed = (tex->mHeight == 0);

		// mesh header
		::fprintf(out,"\t<Texture> \n"
			"\t\t<Integer   name=\"width\"      > %i </Integer>\n",
			"\t\t<Integer   name=\"height\"     > %i </Integer>\n",
			"\t\t<Boolean   name=\"compressed\" > %s </Boolean>\n",
			(compressed ? -1 : tex->mWidth),(compressed ? -1 : tex->mHeight),
			(compressed ? "true" : "false"));

		if (compressed) {
			::fprintf(out,"\t\t<Data length=\"%i\"> %i \n",tex->mWidth);

			if (!shortened) {
				for (unsigned int n = 0; n < tex->mWidth;++n) {
					::fprintf(out,"\t\t\t%2x",tex->pcData[n]);
					if (n && !(n % 50))
						::fprintf(out,"\n");
				}
			}
		}
		else if (!shortened){
			::fprintf(out,"\t\t<Data length=\"%i\"> %i \n",tex->mWidth*tex->mHeight*4);

			const unsigned int width = (unsigned int)log10((double)std::max(tex->mHeight,tex->mWidth))+1;
			for (unsigned int y = 0; y < tex->mHeight;++y) {
				for (unsigned int x = 0; x < tex->mWidth;++x) {
					aiTexel* tx = tex->pcData + y*tex->mWidth+x;
					unsigned int r = tx->r,g=tx->g,b=tx->b,a=tx->a;
					::fprintf(out,"\t\t\t%2x %2x %2x %2x",r,g,b,a);

					// group by four for readibility
					if (0 == (x+y*tex->mWidth) % 4)
						::fprintf(out,"\n");
				}
			}
		}
		::fprintf(out,"\t\t</Data>\n\t</Texture>\n");
	}

	// write materials
	for (unsigned int i = 0; i< scene->mNumMaterials; ++i) {
		const aiMaterial* mat = scene->mMaterials[i];

		::fprintf(out,
			"\t<Material  NumberOfProperties=\"%i\">\n",mat->mNumProperties);

		for (unsigned int n = 0; n < mat->mNumProperties;++n) {
			const aiMaterialProperty* prop = mat->mProperties[n];

			const char* sz = "";
			if (prop->mType == aiPTI_Float) 
				sz = "float";
			else if (prop->mType == aiPTI_Integer) 
				sz = "integer";
			else if (prop->mType == aiPTI_String) 
				sz = "string";
			else if (prop->mType == aiPTI_Buffer) 
				sz = "binary_buffer";

			::fprintf(out,
				"\t\t<MatProperty key=\"%s\" \n\t\t\ttype=\"%s\" tex_usage=\"%s\" tex_index=\"%i\"",
				prop->mKey.data, sz,
				TextureTypeToString((aiTextureType)prop->mSemantic),prop->mIndex);

			if (prop->mType == aiPTI_Float) {
				::fprintf(out,
				" size=\"%i\">\n\t\t\t",
				prop->mDataLength/sizeof(float));
				
				for (unsigned int p = 0; p < prop->mDataLength/sizeof(float);++p)
					::fprintf(out,"%f ",*((float*)(prop->mData+p*sizeof(float))));
			}
			else if (prop->mType == aiPTI_Integer) {
				::fprintf(out,
				" size=\"%i\">\n\t\t\t",
				prop->mDataLength/sizeof(int));

				for (unsigned int p = 0; p < prop->mDataLength/sizeof(int);++p)
					::fprintf(out,"%i ",*((int*)(prop->mData+p*sizeof(int))));
			}
			else if (prop->mType == aiPTI_Buffer) {
				::fprintf(out,
				" size=\"%i\">\n\t\t\t",
				prop->mDataLength);
				
				for (unsigned int p = 0; p < prop->mDataLength;++p) {
					::fprintf(out,"%2x ",prop->mData[p]);
					if (p && 0 == p%30)
						::fprintf(out,"\n\t\t\t");
				}
			}
			else if (prop->mType == aiPTI_String) {
				::fprintf(out,">\n\t\t\t\"%s\"",prop->mData+4 /* skip length */);
			}
			::fprintf(out,"\n\t\t</MatProperty>\n");
		}
		::fprintf(out,"\t</Material>\n");
	}

	// write animations
	for (unsigned int i = 0; i < scene->mNumAnimations;++i) {
		aiAnimation* anim = scene->mAnimations[i];

		// anim header
		ConvertName(name,anim->mName);
		::fprintf(out,"\t<Animation name=\"%s\">\n"
			"\t\t<Integer name=\"num_chan\" > %i </Integer>\n"
			"\t\t<Float   name=\"duration\" > %e </Float>\n"
			"\t\t<Float   name=\"tick_cnt\" > %e </Float>\n",
			name.data, anim->mNumChannels,anim->mDuration, anim->mTicksPerSecond);

		// write bone animation channels
		for (unsigned int n = 0; n < anim->mNumChannels;++n) {
			aiNodeAnim* nd = anim->mChannels[n];

			// node anim header
			ConvertName(name,nd->mNodeName);
			::fprintf(out,"\t\t<Channel node=\"%s\">\n"
				"\t\t\t<Integer name=\"num_pos_keys\" > %i </Integer>\n"
				"\t\t\t<Integer name=\"num_scl_keys\" > %i </Integer>\n"
				"\t\t\t<Integer name=\"num_rot_keys\" > %i </Integer>\n",
				name.data,nd->mNumPositionKeys,nd->mNumScalingKeys,nd->mNumRotationKeys);

			if (!shortened) {
				// write position keys
				for (unsigned int a = 0; a < nd->mNumPositionKeys;++a) {
					aiVectorKey* vc = nd->mPositionKeys+a;
					::fprintf(out,"\t\t\t<PositionKey time=\"%e\">\n"
						"\t\t\t\t%0 8f %0 8f %0 8f\n\t\t\t</PositionKey>\n",
						vc->mTime,vc->mValue.x,vc->mValue.y,vc->mValue.z,a);
				}

				// write scaling keys
				for (unsigned int a = 0; a < nd->mNumScalingKeys;++a) {
					aiVectorKey* vc = nd->mScalingKeys+a;
					::fprintf(out,"\t\t\t<ScalingKey time=\"%e\">\n"
						"\t\t\t\t%0 8f %0 8f %0 8f\n\t\t\t</ScalingKey>\n",
						vc->mTime,vc->mValue.x,vc->mValue.y,vc->mValue.z,a);
				}

				// write rotation keys
				for (unsigned int a = 0; a < nd->mNumRotationKeys;++a) {
					aiQuatKey* vc = nd->mRotationKeys+a;
					::fprintf(out,"\t\t\t<RotationKey time=\"%e\">\n"
						"\t\t\t\t%0 8f %0 8f %0 8f %0 8f\n\t\t\t</RotationKey>\n",
						vc->mTime,vc->mValue.x,vc->mValue.y,vc->mValue.z,vc->mValue.w,a);
				}
			}
			::fprintf(out,"\t\t</Channel>\n",n);
		}
		::fprintf(out,"\t</Animation>\n",i);
	}

	// write meshes
	for (unsigned int i = 0; i < scene->mNumMeshes;++i) {
		aiMesh* mesh = scene->mMeshes[i];
		const unsigned int width = (unsigned int)log10((double)mesh->mNumVertices)+1;

		// mesh header
		::fprintf(out,"\t<Mesh types=\"%s %s %s %s\">\n"
			"\t\t<Integer name=\"num_verts\" > %i </Integer>\n"
			"\t\t<Integer name=\"num_faces\" > %i </Integer>\n",
			(mesh->mPrimitiveTypes & aiPrimitiveType_POINT    ? "points"    : ""),
			(mesh->mPrimitiveTypes & aiPrimitiveType_LINE     ? "lines"     : ""),
			(mesh->mPrimitiveTypes & aiPrimitiveType_TRIANGLE ? "triangles" : ""),
			(mesh->mPrimitiveTypes & aiPrimitiveType_POLYGON  ? "polygons"  : ""),
			mesh->mNumVertices,mesh->mNumFaces);

		// bones
		for (unsigned int n = 0; n < mesh->mNumBones;++n) {
			aiBone* bone = mesh->mBones[n];

			ConvertName(name,bone->mName);
			// bone header
			::fprintf(out,"\t\t<Bone name=\"%s\">\n"
				"\t\t\t<Matrix4 name=\"offset\" > \n"
				"\t\t\t\t%0 6f %0 6f %0 6f %0 6f\n"
				"\t\t\t\t%0 6f %0 6f %0 6f %0 6f\n"
				"\t\t\t\t%0 6f %0 6f %0 6f %0 6f\n"
				"\t\t\t\t%0 6f %0 6f %0 6f %0 6f\n"
				"\t\t\t</Matrix4> \n"
				"\t\t\t<Integer name=\"num_weights\" > %i </Integer>\n",
				name.data,
				bone->mOffsetMatrix.a1,bone->mOffsetMatrix.a2,bone->mOffsetMatrix.a3,bone->mOffsetMatrix.a4,
				bone->mOffsetMatrix.b1,bone->mOffsetMatrix.b2,bone->mOffsetMatrix.b3,bone->mOffsetMatrix.b4,
				bone->mOffsetMatrix.c1,bone->mOffsetMatrix.c2,bone->mOffsetMatrix.c3,bone->mOffsetMatrix.c4,
				bone->mOffsetMatrix.d1,bone->mOffsetMatrix.d2,bone->mOffsetMatrix.d3,bone->mOffsetMatrix.d4,
				bone->mNumWeights);

			if (!shortened) {
				// bone weights
				for (unsigned int a = 0; a < bone->mNumWeights;++a) {
					aiVertexWeight* wght = bone->mWeights+a;

					::fprintf(out,"\t\t\t<VertexWeight index=\"%i\">\n\t\t\t\t%f\n\t\t\t</VertexWeight>\n",
						wght->mVertexId,wght->mWeight);
				}
			}
			::fprintf(out,"\t\t</Bone>\n",n);
		}

		// faces
		if (!shortened) {
			for (unsigned int n = 0; n < mesh->mNumFaces; ++n) {
				aiFace& f = mesh->mFaces[n];
				::fprintf(out,"\t\t<Face num_indices=\"%i\">\n"
					"\t\t\t",f.mNumIndices);

				for (unsigned int j = 0; j < f.mNumIndices;++j)
					::fprintf(out,"%i ",f.mIndices[j]);

				::fprintf(out,"\n\t\t</Face>\n");
			}
		}

		// vertex positions
		if (mesh->HasPositions()) {
			::fprintf(out,"\t\t<Positions> \n");
			if (!shortened) {
				for (unsigned int n = 0; n < mesh->mNumVertices; ++n) {
					::fprintf(out,"\t\t%0 8f %0 8f %0 8f\n",
						mesh->mVertices[n].x,
						mesh->mVertices[n].y,
						mesh->mVertices[n].z);
				}
			}
			else {
			}
			::fprintf(out,"\t\t</Positions>\n");
		}

		// vertex normals
		if (mesh->HasNormals()) {
			::fprintf(out,"\t\t<Normals> \n");
			if (!shortened) {
				for (unsigned int n = 0; n < mesh->mNumVertices; ++n) {
					::fprintf(out,"\t\t%0 8f %0 8f %0 8f\n",
						mesh->mNormals[n].x,
						mesh->mNormals[n].y,
						mesh->mNormals[n].z);
				}
			}
			else {
			}
			::fprintf(out,"\t\t</Normals>\n");
		}

		// vertex tangents and bitangents
		if (mesh->HasTangentsAndBitangents()) {
			::fprintf(out,"\t\t<Tangents> \n");
			if (!shortened) {
				for (unsigned int n = 0; n < mesh->mNumVertices; ++n) {
					::fprintf(out,"\t\t%0 8f %0 8f %0 8f \t %0 8f %0 8f %0 8f\n",
						mesh->mTangents[n].x,
						mesh->mTangents[n].y,
						mesh->mTangents[n].z,
						mesh->mBitangents[n].x,
						mesh->mBitangents[n].y,
						mesh->mBitangents[n].z);
				}
			}
			else {
			}
			::fprintf(out,"\t\t</Tangents>\n");
		}

		// texture coordinates
		for (unsigned int a = 0; a < AI_MAX_NUMBER_OF_TEXTURECOORDS; ++a) {
			if (!mesh->mTextureCoords[a])
				break;

			::fprintf(out,"\t\t<TextureCoords set=\"%i\" num_components=\"%i\"> \n",a,mesh->mNumUVComponents[a]);
			if (!shortened) {
				for (unsigned int n = 0; n < mesh->mNumVertices; ++n) {
					::fprintf(out,"\t\t%0 8f %0 8f %0 8f\n",
						mesh->mTextureCoords[a][n].x,
						mesh->mTextureCoords[a][n].y,
						mesh->mTextureCoords[a][n].z);
				}
			}
			else {
			}
			::fprintf(out,"\t\t</TextureCoords>\n");
		}

		// vertex colors
		for (unsigned int a = 0; a < AI_MAX_NUMBER_OF_COLOR_SETS; ++a) {
			if (!mesh->mColors[a])
				break;
			//::fprintf(out,"\t\t<Colors set=\"%i\"> \n",a);
			if (!shortened) {
				for (unsigned int n = 0; n < mesh->mNumVertices; ++n) {
					::fprintf(out,"\t\t%0 8f %0 8f %0 8f %0 8f\n",
						mesh->mColors[a][n].r,
						mesh->mColors[a][n].g,
						mesh->mColors[a][n].b,
						mesh->mColors[a][n].a);
				}
			}
			else {
			}
			::fprintf(out,"\t\t</Color>\n");
		}
		::fprintf(out,"\t</Mesh>\n");
	}
	::fprintf(out,"</Scene>\n</ASSIMP>");
}
示例#25
0
文件: MXTree.cpp 项目: jsc0218/MxTree
void MXTree::Split(GiSTnode **node, const GiSTentry& entry)
{
	double radii[2], dist, *dists = new double[(*node)->NumEntries()*2];
	int pageNums[2], cands[2];
	vector<vector<int>> vec(2);
	((MXTnode *)(*node))->TestPromotion(radii, &dist, pageNums, cands, dists, vec);
	if (Trade((*node)->Path().IsRoot(), radii, dist, pageNums, ((MXTnode *)(*node))->GetPageNum()+1, (*node)->NumEntries())) {
		// don't split now
		delete[] dists;
		GiSTpath oldPath = (*node)->Path();

		int startPage = ((*node)->Path().IsRoot() ? rootPage : (*node)->Path().Page());
		int pageNum = ((MXTnode *)(*node))->GetPageNum();
		((MXTfile *)store)->Deallocate(startPage, pageNum);
		startPage = ((MXTfile *)store)->Allocate(++pageNum);
		(*node)->Path().MakeSibling(startPage);
		rootPage = ((*node)->Path().IsRoot() ? startPage : rootPage);
		((MXTnode *)(*node))->SetPageNum(pageNum);
		WriteNode(*node);

		if (!(*node)->Path().IsRoot() && startPage != oldPath.Page()) {
			GiSTpath parentPath = oldPath;
			parentPath.MakeParent();
			GiSTnode *parentNode = ReadNode(parentPath);
			GiSTentry *e = parentNode->SearchPtr(oldPath.Page());
			assert(e != NULL);
			int pos = e->Position();
			e->SetPtr(startPage);
			parentNode->DeleteEntry(pos);
			parentNode->InsertBefore(*e, pos);
			WriteNode(parentNode);
			delete parentNode;
			delete e;
		}
	} else {
		// split now
		bool bLeft = false, bNewRoot = false;

		if ((*node)->Path().IsRoot()) {
			bNewRoot = true;
			(*node)->Path().MakeChild(rootPage);
			rootPage = store->Allocate();
		}

		int oldPageNum = ((MXTnode *)(*node))->GetPageNum();
		GiSTnode *node2 = ((MXTnode *)(*node))->PickSplit(cands, dists, vec);
		delete[] dists;
		int curPageNum = ((MXTnode *)(*node))->GetPageNum();
		assert(oldPageNum >= curPageNum);
		if (oldPageNum > curPageNum) {
			((MXTfile *)store)->Deallocate((*node)->Path().Page()+curPageNum, oldPageNum-curPageNum);
		}
		node2->Path().MakeSibling(((MXTfile *)store)->Allocate(((MXTnode *)node2)->GetPageNum()));

		WriteNode(*node);
		WriteNode(node2);
	
		GiSTentry *e = (*node)->SearchPtr(entry.Ptr());
		if (e != NULL) {
			bLeft = true;
			delete e;
		}
	
		GiSTentry *e1 = (*node)->Union();
		GiSTentry *e2 = node2->Union();
	
		e1->SetPtr((*node)->Path().Page());
		e2->SetPtr(node2->Path().Page());
		// Create new root if root is being split
		if (bNewRoot) {
			GiSTnode *root = NewNode(this);
			root->SetLevel((*node)->Level() + 1);
			root->InsertBefore(*e1, 0);
			root->InsertBefore(*e2, 1);
			root->Path().MakeRoot();
			WriteNode(root);
			delete root;
		} else {
			// Insert entry for N' in parent
			GiSTpath parentPath = (*node)->Path();
			parentPath.MakeParent();
			GiSTnode *parent = ReadNode(parentPath);
			// Find the entry for N in parent
			GiSTentry *e = parent->SearchPtr((*node)->Path().Page());
			assert(e != NULL);
			// Insert the new entry right after it
			int pos = e->Position();
			parent->DeleteEntry(pos);
			parent->InsertBefore(*e1, pos);
			parent->InsertBefore(*e2, pos+1);
			delete e;
			if (!parent->IsOverFull(*store)) {
				WriteNode(parent);
			} else {
				Split(&parent, bLeft? *e1: *e2);  // parent is the node which contains the entry inserted
				GiSTpage page = (*node)->Path().Page();
				(*node)->Path() = parent->Path();  // parent's path may change
				(*node)->Path().MakeChild(page);
				page = node2->Path().Page();
				node2->Path() = (*node)->Path();
				node2->Path().MakeSibling(page);
			}
			delete parent;
		}
		if (!bLeft) {
			delete *node;
			*node = node2;  // return it
		} else {
			delete node2;
		}
		delete e1;
		delete e2;
	}
}
示例#26
0
 void WriteGraph(QualType Type) {
   Out << "digraph \"" << DOT::EscapeString(Type.getAsString()) << "\" {\n";
   WriteNode(Type, false);
   Out << "}\n";
 }