示例#1
0
void RenderTerrain::createIndexBuffer()
{
	/* 地形的三角带示意图如下:
	6---7---8
	| \ | \ |
	3---4---5
	| / | / |
	0---1---2
	索引:(2,5,1,4,0,3,3,6,4,7,5,8)
	*/
	uint16 batchSize = getBatchSize();

	RenderIndexBufferDesc ibdesc;
	ibdesc.maxIndices = RenderTerrain::_getNumIndexesForBatchSize(batchSize);

	m_indexBuffer = GearApplication::getApp()->getRender()->createIndexBuffer(ibdesc);

	uint16* pI = static_cast<uint16*>(m_indexBuffer->lock());
	size_t rowSize = batchSize;
	size_t numRows = batchSize - 1;

	uint16 currentVertex = batchSize - 1;

	bool rightToLeft = true; //左右交替
	for (uint16 r = 0; r < numRows; ++r)
	{
		for (uint16 c = 0; c < batchSize; ++c)
		{
			*pI++ = currentVertex;
			*pI++ = currentVertex + rowSize;

			if (c+1 < batchSize)
			{
				currentVertex = rightToLeft ? currentVertex - 1 : currentVertex + 1;
			}				
		}
		rightToLeft = !rightToLeft;
		currentVertex += rowSize;
		*pI++ = currentVertex;
	}
	m_indexBuffer->unlock();
}
示例#2
0
	string MemoryDataLayer::convet2CaffeFormat()
	{
		string layerStrStart = "layer\n{\n";
		string layerStrEnd = "}";

		string nameStrStart = "\tname: \"";
		string nameStrEnd = "\"\n";

		string typeStrStart = "\ttype: \"";
		string typeStrEnd = "\"\n";

		string topStrStart = "\ttop: \"";
		string topStrEnd = "\"\n";

		string bottomStrStart = "\tbottom: \"";
		string bottomStrEnd = "\"\n";

		string memoryDataParamStrStart = "\tmemory_data_param\n\t{\n";
		string memoryDataParamStrEnd = "\t}\n";

		string batchSizeStrStart = "\t\tbatch_size: ";
		string batchSizeEnd = "\n";

		string channelsStrStart = "\t\tchannels: ";
		string channelsEnd = "\n";

		string heightStrStart = "\t\theight: ";
		string heightEnd = "\n";

		string widthStrStart = "\t\twidth: ";
		string widthEnd = "\n";

		string phaseStrStart = "\tinclude:\n\t{\n";		
		string phaseStrEnd = "\t}\n";

		string phaseStateStrStart = "\t\tphase: ";
		string phaseStateStrEnd = "\n";

		string outStr = layerStrStart + 
						nameStrStart + mName + nameStrEnd + 
						typeStrStart + getLayerType() + typeStrEnd;

		for(size_t i = 0; i < mTops->size(); i++)
		{
			outStr = outStr + topStrStart + (*mTops)[i] + topStrEnd;
		}
		
		for(size_t i = 0; i < mBottoms->size(); i++)
		{
			outStr = outStr + bottomStrStart + (*mBottoms)[i] + bottomStrEnd;
		}

		outStr = outStr + 
				 memoryDataParamStrStart + 
				 batchSizeStrStart + to_string(getBatchSize()) + batchSizeEnd +
				 channelsStrStart + to_string(getChannels()) + channelsEnd +
				 heightStrStart + to_string(getHeight()) + heightEnd +
				 widthStrStart + to_string(getWidth()) + widthEnd +
				 memoryDataParamStrEnd;

		if (mPhase != Phase::BOTH)
		{
			outStr += phaseStrStart + phaseStateStrStart;

			if (mPhase == Phase::TRAIN)
			{
				outStr += "TRAIN";
			}
			else if (mPhase == Phase::TEST)
			{
				outStr += "TEST";
			}

			outStr += phaseStateStrEnd + phaseStrEnd;
		}
		
		outStr += layerStrEnd;

		return outStr;
	}
示例#3
0
	string WindowDataLayer::convet2CaffeFormat()
	{
		string layerStrStart = "layer\n{\n";
		string layerStrEnd = "}";

		string nameStrStart = "\tname: \"";
		string nameStrEnd = "\"\n";

		string typeStrStart = "\ttype: \"";
		string typeStrEnd = "\"\n";

		string topStrStart = "\ttop: \"";
		string topStrEnd = "\"\n";

		string bottomStrStart = "\tbottom: \"";
		string bottomStrEnd = "\"\n";

		string WindowDataParamStrStart = "\twindow_data_param\n\t{\n";
		string WindowDataParamStrEnd = "\t}\n";

		string SourceStrStart = "\t\tsource: ";
		string SourceStrEnd = "\n";

		string ScaleStrStart = "\t\tscale: ";
		string ScaleStrEnd = "\n";

		string MeanFileStrStart = "\t\tmean_file: ";
		string MeanFileStrEnd = "\n";

		string BatchSizeStrStart = "\t\tbatch_size: ";
		string BatchSizeStrEnd = "\n";

		string CropSizeStrStart = "\t\tcrop_size: ";
		string CropSizeStrEnd = "\n";

		string MirrorStrStart = "\t\tmirror: ";
		string MirrorStrEnd = "\n";

		string FgThresholdStrStrat = "\t\tfg_threshold: ";
		string FgThresholdStrEnd = "\n";

		string BgThresholdStrStrat = "\t\tbg_threshold: ";
		string BgThresholdStrEnd = "\n";

		string FgFractionStrStart = "\t\tfg_fraction: ";
		string FgFractionStrEnd = "\n";

		string ContextPadStrStart = "\t\tcontext_pad: "; 
		string ContextPadStrEnd = "\n";

		string CropModeStrStart = "\t\tcrop_mode: ";
		string CropModeStrEnd = "\n";

		string CacheImagesStrStart = "\t\tcache_images: ";
		string CacheImagesStrEnd = "\n";

		string RootFolderStrStart = "\t\troot_folder: ";
		string RootFolderStrEnd = "\n";

		string phaseStrStart = "\tinclude:\n\t{\n";		
		string phaseStrEnd = "\t}\n";

		string phaseStateStrStart = "\t\tphase: ";
		string phaseStateStrEnd = "\n";

		string outStr =  layerStrStart + 
						 nameStrStart + mName + nameStrEnd + 
						 typeStrStart + getLayerType() + typeStrEnd;

		for(size_t i = 0; i < mTops->size(); i++)
		{
			outStr = outStr + topStrStart + (*mTops)[i] + topStrEnd;
		}

		for(size_t i = 0; i < mBottoms->size(); i++)
		{
			outStr = outStr + bottomStrStart + (*mBottoms)[i] +bottomStrEnd;
		}

		outStr += WindowDataParamStrStart;

		if (getSource() == "")
		{

		}
		else
		{
			outStr += SourceStrStart + "\"" + getSource() + "\"" + SourceStrEnd;;
		}

		if(((WindowDataParam*)mParam)->mScale != 1)
		{
			outStr += ScaleStrStart + to_string(getScale()) + ScaleStrEnd;
		}
		
		if (getMeanFile() == "")
		{

		}
		else
		{
			outStr += MeanFileStrStart + "\"" + getMeanFile() + "\"" + MeanFileStrEnd;
		}

		outStr += BatchSizeStrStart + to_string(getBatchSize()) + BatchSizeStrEnd;

		if(((WindowDataParam*)mParam)->mCropSize != 0)
		{
			outStr += CropSizeStrStart + to_string(getCropSize()) + CropSizeStrEnd;
		}

		if(((WindowDataParam*)mParam)->mMirror != false)
		{
			outStr += MirrorStrStart + "true" + MirrorStrEnd;
		}

		if(((WindowDataParam*)mParam)->mFgThreshold != 0.5)
		{
			outStr += FgThresholdStrStrat + to_string(getFgThreshold()) + FgFractionStrEnd;
		}

		if(((WindowDataParam*)mParam)->mBgThreshold != 0.5)
		{
			outStr += BgThresholdStrStrat + to_string(getBgThreshold()) + BgThresholdStrEnd;
		}

		if(((WindowDataParam*)mParam)->mFgFraction != 0.25)
		{
			outStr += FgFractionStrStart + to_string(getFgFraction()) + FgFractionStrEnd;
		}

		if(((WindowDataParam*)mParam)->mContextPad != 0)
		{
			outStr += ContextPadStrStart + to_string(getContextPad()) + ContextPadStrEnd;
		}

		if(((WindowDataParam*)mParam)->mCropMode != CropMode::WARP)
		{
			outStr += CropModeStrStart + "\"" + "square" + "\"" + CropModeStrEnd;
		}
		
		if(((WindowDataParam*)mParam)->mCacheImages != false)
		{
			outStr +=  CacheImagesStrStart + "true" + CacheImagesStrEnd;
		}

		if(((WindowDataParam*)mParam)->mRootFolder != "")
		{
			outStr +=  RootFolderStrStart + "\"" + getRootFolder() + "\"" + RootFolderStrEnd ;
		}

		outStr += WindowDataParamStrEnd;

		if (mPhase != Phase::BOTH)
		{
			outStr += phaseStrStart + phaseStateStrStart;

			if (mPhase == Phase::TRAIN)
			{
				outStr += "TRAIN";
			}
			else if (mPhase == Phase::TEST)
			{
				outStr += "TEST";
			}

			outStr += phaseStateStrEnd + phaseStrEnd;
		}
		
		outStr += layerStrEnd;
		
		return outStr;
	}
示例#4
0
	string DataLayer::convet2CaffeFormat()
	{
		string layerStrStart = "layer\n{\n";
		string layerStrEnd = "}";

		string nameStrStart = "\tname: \"";
		string nameStrEnd = "\"\n";

		string typeStrStart = "\ttype: \"";
		string typeStrEnd = "\"\n";

		string topStrStart = "\ttop: \"";
		string topStrEnd = "\"\n";

		string bottomStrStart = "\tbottom: \"";
                string bottomStrEnd = "\"\n";

                string transformParamStrStart = "\ttransform_param\n\t{\n";
                string transformParamStrEnd ="\t}\n";

		string dataParamStrStart = "\tdata_param\n\t{\n";
		string dataParamStrEnd ="\t}\n";

		string SourceStrStart = "\t\tsource: ";
		string SourceStrEnd = "\n";

		string batchSizeStrStart = "\t\tbatch_size: ";
		string batchSizeStrEnd = "\n";

		string randSkipStrStart = "\t\trand_skip: ";
		string randSkipStrEnd = "\n";

		string backendStrStart = "\t\tbackend: ";
		string backendStrEnd = "\n";

		string ScaleStrStart = "\t\tscale: ";
		string ScaleStrEnd = "\n";

		string MeanFileStrStart = "\t\tmean_file: ";
		string MeanFileStrEnd = "\n";

		string CropSizeStrStart = "\t\tcrop_size: ";
		string CropSizeStrEnd = "\n";

		string MirrorStrStart = "\t\tmirror: ";
		string MirrorStrEnd = "\n";

		string ForceEncodeColorStrStart = "\t\tforce_encoded_color: ";
		string ForceEncodeColorStrEnd = "\n";

                string PrefetchStrStart =  "\t\tprefetch: ";
                string PrefetchStrEnd = "\n";

		string phaseStrStart = "\tinclude:\n\t{\n";		
		string phaseStrEnd = "\t}\n";

		string phaseStateStrStart = "\t\tphase: ";
		string phaseStateStrEnd = "\n";

		string outStr =  layerStrStart + 
						 nameStrStart + getLayerName() + nameStrEnd + 
						 typeStrStart + getLayerType() + typeStrEnd;

		for(size_t i = 0; i < mTops->size(); i++)
		{
			outStr = outStr + topStrStart + (*mTops)[i] + topStrEnd;
		}

		for(size_t i = 0; i < mBottoms->size(); i++)
		{
			outStr = outStr + bottomStrStart + (*mBottoms)[i] +bottomStrEnd;
		}

                outStr += transformParamStrStart;

                if(((DataParam*)mParam)->mScale != 1)
                {
                        outStr += ScaleStrStart + to_string(getScale()) + ScaleStrEnd;
                }

                if (getMeanfile() != "")
                {
                        outStr += MeanFileStrStart + "\"" + getMeanfile() + "\"" + MeanFileStrEnd;
                }

                if(((DataParam*)mParam)->mCropsize != 0)
                {
                        outStr += CropSizeStrStart + to_string(getCropsize()) + CropSizeStrEnd;
                }

                if(((DataParam*)mParam)->mMirror != false)
                {
                        outStr += MirrorStrStart + "true" + MirrorStrEnd;
                }
                outStr += transformParamStrEnd;

		outStr += dataParamStrStart;

                if (getSource() != "")
		{
			outStr += SourceStrStart + "\"" + getSource() + "\"" + SourceStrEnd;
		}

		outStr +=batchSizeStrStart + to_string(getBatchSize()) + batchSizeStrEnd;

		if(((DataParam*)mParam)->mRandSkip != 0)
		{
			outStr += randSkipStrStart + to_string(getRandSkip()) + randSkipStrEnd;
		}

		if(((DataParam*)mParam)->mBackend != DB::LEVELDB)
		{
			switch (((DataParam*)mParam)->mBackend)
			{
			case DB::LEVELDB:
					outStr += backendStrStart + "LEVELDB" + backendStrEnd;
					break;

			case DB::LMDB:
					outStr += backendStrStart + "LMDB" + backendStrEnd;
					break;
			}
		}

		if(((DataParam*)mParam)->mForceEncodedcolor != false)
		{
			outStr += ForceEncodeColorStrStart + "true" + ForceEncodeColorStrEnd;
		}

                if(((DataParam*)mParam)->mPrefetch != 4)
                {
                        outStr += PrefetchStrStart + to_string(getPrefetch())  + PrefetchStrEnd;
                }

		outStr += dataParamStrEnd;

		if (mPhase != Phase::BOTH)
		{
			outStr += phaseStrStart + phaseStateStrStart;

			if (mPhase == Phase::TRAIN)
			{
				outStr += "TRAIN";
			}
			else if (mPhase == Phase::TEST)
			{
				outStr += "TEST";
			}

			outStr += phaseStateStrEnd + phaseStrEnd;
		}
		
		outStr += layerStrEnd;

		return outStr;
	}
StatusWith<Message> downconvertFindCommandRequest(const RemoteCommandRequest& request) {
    const auto& cmdObj = request.cmdObj;
    const NamespaceString nss(request.dbname, cmdObj.firstElement().String());
    if (!nss.isValid()) {
        return {ErrorCodes::InvalidNamespace,
                str::stream() << "Invalid collection name: " << nss.ns()};
    }

    const std::string& ns = nss.ns();

    // It is a little heavy handed to use QueryRequest to convert the command object to
    // query() arguments but we get validation and consistent behavior with the find
    // command implementation on the remote server.
    auto qrStatus = QueryRequest::makeFromFindCommand(nss, cmdObj, false);
    if (!qrStatus.isOK()) {
        return qrStatus.getStatus();
    }

    auto qr = std::move(qrStatus.getValue());

    // We are downconverting a find command, and find command can only have ntoreturn
    // if it was generated by mongos.
    invariant(!qr->getNToReturn());
    Query query(qr->getFilter());
    if (!qr->getSort().isEmpty()) {
        query.sort(qr->getSort());
    }
    if (!qr->getHint().isEmpty()) {
        query.hint(qr->getHint());
    }
    if (!qr->getMin().isEmpty()) {
        query.minKey(qr->getMin());
    }
    if (!qr->getMax().isEmpty()) {
        query.minKey(qr->getMax());
    }
    if (qr->isExplain()) {
        query.explain();
    }
    if (qr->isSnapshot()) {
        query.snapshot();
    }

    const int nToReturn = qr->getLimit().value_or(0) * -1;
    const int nToSkip = qr->getSkip().value_or(0);
    const BSONObj* fieldsToReturn = &qr->getProj();
    int queryOptions = qr->getOptions();  // non-const so we can set slaveOk if we need to
    const int batchSize = qr->getBatchSize().value_or(0);

    const int nextBatchSize = [batchSize, nToReturn]() {
        if (nToReturn == 0)
            return batchSize;
        if (batchSize == 0)
            return nToReturn;
        return batchSize < nToReturn ? batchSize : nToReturn;
    }();

    // We can't downconvert all metadata, since we aren't sending a command, but we do need to
    // downconvert $secondaryOk to the slaveOK bit.
    auto ssm = rpc::ServerSelectionMetadata::readFromMetadata(
        request.metadata.getField(rpc::ServerSelectionMetadata::fieldName()));
    if (!ssm.isOK()) {
        return ssm.getStatus();
    }
    if (ssm.getValue().isSecondaryOk()) {
        queryOptions |= mongo::QueryOption_SlaveOk;
    }

    Message message;
    assembleQueryRequest(
        ns, query.obj, nextBatchSize, nToSkip, fieldsToReturn, queryOptions, message);

    return {std::move(message)};
}