bool KMeansFeatures::computeFeatures(const VectorDouble &inputVector){ VectorDouble data( numInputDimensions ); //Scale the input data if needed, if not just copy it if( useScaling ){ for(UINT j=0; j<numInputDimensions; j++){ data[j] = scale(inputVector[j],ranges[j].minValue,ranges[j].maxValue,0,1); } }else{ for(UINT j=0; j<numInputDimensions; j++){ data[j] = inputVector[j]; } } const UINT numLayers = getNumLayers(); for(UINT layer=0; layer<numLayers; layer++){ if( !projectDataThroughLayer(data, featureVector, layer) ){ errorLog << "computeFeatures(const VectorDouble &inputVector) - Failed to project data through layer: " << layer << endl; return false; } //The output of the current layer will become the input to the next layer unless it is the last layer if( layer+1 < numLayers ){ data = featureVector; } } return true; }
std::size_t DPSketch::getNumPoints() const { std::size_t numPoints = 0; for(std::size_t i = 0; i < getNumLayers(); ++i) { numPoints += _layers[i].getNumPoints(); } return numPoints; }
PopupMenu CtrlrPanelCanvas::getLayerMenu() { PopupMenu m; for (int i=0; i<getNumLayers(); i++) { m.addItem (i+4096, getLayerName(i)); } return (m); }
std::string DPSketch::getSketchStats() const { std::stringstream ss; ss << "[DPSketch:"; ss << " #layers: " << getNumLayers(); ss << " #traces: " << getNumTraces(); ss << " #points: " << getNumPoints(); ss << "]"; ss << std::endl; return ss.str(); }
ErrVal VUI::writeSVCExtension( HeaderSymbolWriteIf* pcWriteIf ) const { ROF( getNumLayers() ); RNOK( pcWriteIf->writeUvlc( getNumLayers() - 1, "SPS: num_layers_minus1" ) ); for( UInt uiLayer = 0; uiLayer < getNumLayers(); uiLayer++ ) { RNOK( m_acLayerInfo.get(uiLayer).write( pcWriteIf ) ); RNOK( m_acTimingInfo.get(uiLayer).write( pcWriteIf ) ); RNOK( m_acNalHrd.get(uiLayer).write( pcWriteIf ) ); RNOK( m_acVclHrd.get(uiLayer).write( pcWriteIf ) ); if( m_acNalHrd.get(uiLayer).getHrdParametersPresentFlag() || m_acVclHrd.get(uiLayer).getHrdParametersPresentFlag() ) { RNOK( pcWriteIf->writeFlag( m_abLowDelayHrdFlag.get(uiLayer), "VUI: low_delay_hrd_flag")); } RNOK( pcWriteIf->writeFlag( m_abPicStructPresentFlag.get(uiLayer), "VUI: pic_struct_present_flag")); } return Err::m_nOK; }
bool KMeansFeatures::saveModelToFile(fstream &file) const{ if( !file.is_open() ){ errorLog << "saveModelToFile(fstream &file) - The file is not open!" << endl; return false; } //First, you should add a header (with no spaces) e.g. file << "KMEANS_FEATURES_FILE_V1.0" << endl; //Second, you should save the base feature extraction settings to the file if( !saveFeatureExtractionSettingsToFile( file ) ){ errorLog << "saveFeatureExtractionSettingsToFile(fstream &file) - Failed to save base feature extraction settings to file!" << endl; return false; } file << "NumLayers: " << getNumLayers() << endl; file << "NumClustersPerLayer: "; for(UINT i=0; i<numClustersPerLayer.size(); i++){ file << " " << numClustersPerLayer[i]; } file << endl; file << "Alpha: " << alpha << endl; if( trained ){ file << "Ranges: "; for(UINT i=0; i<ranges.size(); i++){ file << ranges[i].minValue << " " << ranges[i].maxValue << " "; } file << endl; file << "Clusters: " << endl; for(UINT k=0; k<clusters.size(); k++){ file << "NumRows: " << clusters[k].getNumRows() << endl; file << "NumCols: " << clusters[k].getNumCols() << endl; for(UINT i=0; i<clusters[k].getNumRows(); i++){ for(UINT j=0; j<clusters[k].getNumCols(); j++){ file << clusters[k][i][j]; if( j+1 < clusters[k].getNumCols() ) file << "\t"; } file << endl; } } } return true; }
void SparseShaderIntrinsicsCaseSampledBase::initPrograms (vk::SourceCollections& programCollection) const { const deUint32 numLayers = getNumLayers(m_imageType, m_imageSize); const std::string coordString = getShaderImageCoordinates(m_imageType, "%local_texCoord_x", "%local_texCoord_xy", "%local_texCoord_xyz"); // Create vertex shader std::ostringstream vs; vs << "#version 440\n" << "layout(location = 0) in highp vec2 vs_in_position;\n" << "layout(location = 1) in highp vec2 vs_in_texCoord;\n" << "\n" << "layout(location = 0) out highp vec3 vs_out_texCoord;\n" << "\n" << "out gl_PerVertex {\n" << " vec4 gl_Position;\n" << "};\n" << "void main (void)\n" << "{\n" << " gl_Position = vec4(vs_in_position, 0.0f, 1.0f);\n" << " vs_out_texCoord = vec3(vs_in_texCoord, 0.0f);\n" << "}\n"; programCollection.glslSources.add("vertex_shader") << glu::VertexSource(vs.str()); if (numLayers > 1u) { const deInt32 maxVertices = 3u * numLayers; // Create geometry shader std::ostringstream gs; gs << "#version 440\n" << "layout(triangles) in;\n" << "layout(triangle_strip, max_vertices = " << static_cast<deInt32>(maxVertices) << ") out;\n" << "\n" << "in gl_PerVertex {\n" << " vec4 gl_Position;\n" << "} gl_in[];\n" << "out gl_PerVertex {\n" << " vec4 gl_Position;\n" << "};\n" << "layout(location = 0) in highp vec3 gs_in_texCoord[];\n" << "\n" << "layout(location = 0) out highp vec3 gs_out_texCoord;\n" << "\n" << "void main (void)\n" << "{\n" << " for (int layerNdx = 0; layerNdx < " << static_cast<deInt32>(numLayers) << "; ++layerNdx)\n" << " {\n" << " for (int vertexNdx = 0; vertexNdx < gl_in.length(); ++vertexNdx)\n" << " {\n" << " gl_Layer = layerNdx;\n" << " gl_Position = gl_in[vertexNdx].gl_Position;\n" << " gs_out_texCoord = vec3(gs_in_texCoord[vertexNdx].xy, float(layerNdx));\n" << " EmitVertex();\n" << " }\n" << " EndPrimitive();\n" << " }\n" << "}\n"; programCollection.glslSources.add("geometry_shader") << glu::GeometrySource(gs.str()); } // Create fragment shader std::ostringstream fs; const std::string typeImgComp = getImageComponentTypeName(m_format); const std::string typeImgCompVec4 = getImageComponentVec4TypeName(m_format); fs << "OpCapability Shader\n" << "OpCapability SampledCubeArray\n" << "OpCapability ImageCubeArray\n" << "OpCapability SparseResidency\n" << "OpCapability StorageImageExtendedFormats\n" << "%ext_import = OpExtInstImport \"GLSL.std.450\"\n" << "OpMemoryModel Logical GLSL450\n" << "OpEntryPoint Fragment %func_main \"main\" %varying_texCoord %output_texel %output_residency\n" << "OpExecutionMode %func_main OriginUpperLeft\n" << "OpSource GLSL 440\n" << "OpName %func_main \"main\"\n" << "OpName %varying_texCoord \"varying_texCoord\"\n" << "OpName %output_texel \"out_texel\"\n" << "OpName %output_residency \"out_residency\"\n" << "OpName %type_uniformblock \"LodBlock\"\n" << "OpMemberName %type_uniformblock 0 \"lod\"\n" << "OpMemberName %type_uniformblock 1 \"size\"\n" << "OpName %uniformblock_instance \"lodInstance\"\n" << "OpName %uniformconst_image_sparse \"u_imageSparse\"\n" << "OpDecorate %varying_texCoord Location 0\n" << "OpDecorate %output_texel Location 0\n" << "OpDecorate %output_residency Location 1\n" << "OpDecorate %type_uniformblock Block\n" << "OpMemberDecorate %type_uniformblock 0 Offset 0\n" << "OpMemberDecorate %type_uniformblock 1 Offset 8\n" << "OpDecorate %uniformconst_image_sparse DescriptorSet 0\n" << "OpDecorate %uniformconst_image_sparse Binding " << BINDING_IMAGE_SPARSE << "\n" << "%type_void = OpTypeVoid\n" << "%type_void_func = OpTypeFunction %type_void\n" << "%type_bool = OpTypeBool\n" << "%type_int = OpTypeInt 32 1\n" << "%type_uint = OpTypeInt 32 0\n" << "%type_float = OpTypeFloat 32\n" << "%type_vec2 = OpTypeVector %type_float 2\n" << "%type_vec3 = OpTypeVector %type_float 3\n" << "%type_vec4 = OpTypeVector %type_float 4\n" << "%type_ivec4 = OpTypeVector %type_int 4\n" << "%type_uvec4 = OpTypeVector %type_uint 4\n" << "%type_uniformblock = OpTypeStruct %type_uint %type_vec2\n" << "%type_struct_int_img_comp_vec4 = OpTypeStruct %type_int " << typeImgCompVec4 << "\n" << "%type_input_vec3 = OpTypePointer Input %type_vec3\n" << "%type_input_float = OpTypePointer Input %type_float\n" << "%type_output_img_comp_vec4 = OpTypePointer Output " << typeImgCompVec4 << "\n" << "%type_output_uint = OpTypePointer Output %type_uint\n" << "%type_function_int = OpTypePointer Function %type_int\n" << "%type_function_img_comp_vec4 = OpTypePointer Function " << typeImgCompVec4 << "\n" << "%type_function_int_img_comp_vec4 = OpTypePointer Function %type_struct_int_img_comp_vec4\n" << "%type_pushconstant_uniformblock = OpTypePointer PushConstant %type_uniformblock\n" << "%type_pushconstant_uniformblock_member_lod = OpTypePointer PushConstant %type_uint\n" << "%type_pushconstant_uniformblock_member_size = OpTypePointer PushConstant %type_vec2\n" << "%type_image_sparse = " << getOpTypeImageSparse(m_imageType, m_format, typeImgComp, true) << "\n" << "%type_sampled_image_sparse = OpTypeSampledImage %type_image_sparse\n" << "%type_uniformconst_image_sparse = OpTypePointer UniformConstant %type_sampled_image_sparse\n" << "%varying_texCoord = OpVariable %type_input_vec3 Input\n" << "%output_texel = OpVariable %type_output_img_comp_vec4 Output\n" << "%output_residency = OpVariable %type_output_uint Output\n" << "%uniformconst_image_sparse = OpVariable %type_uniformconst_image_sparse UniformConstant\n" << "%uniformblock_instance = OpVariable %type_pushconstant_uniformblock PushConstant\n" // Declare constants << "%constant_uint_0 = OpConstant %type_uint 0\n" << "%constant_uint_1 = OpConstant %type_uint 1\n" << "%constant_uint_2 = OpConstant %type_uint 2\n" << "%constant_uint_3 = OpConstant %type_uint 3\n" << "%constant_int_0 = OpConstant %type_int 0\n" << "%constant_int_1 = OpConstant %type_int 1\n" << "%constant_int_2 = OpConstant %type_int 2\n" << "%constant_int_3 = OpConstant %type_int 3\n" << "%constant_float_0 = OpConstant %type_float 0.0\n" << "%constant_float_half = OpConstant %type_float 0.5\n" << "%constant_texel_resident = OpConstant %type_uint " << MEMORY_BLOCK_BOUND_VALUE << "\n" << "%constant_texel_not_resident = OpConstant %type_uint " << MEMORY_BLOCK_NOT_BOUND_VALUE << "\n" // Call main function << "%func_main = OpFunction %type_void None %type_void_func\n" << "%label_func_main = OpLabel\n" << "%local_image_sparse = OpLoad %type_sampled_image_sparse %uniformconst_image_sparse\n" << "%texCoord = OpLoad %type_vec3 %varying_texCoord\n" << "%local_texCoord_x = OpCompositeExtract %type_float %texCoord 0\n" << "%local_texCoord_y = OpCompositeExtract %type_float %texCoord 1\n" << "%local_texCoord_z = OpCompositeExtract %type_float %texCoord 2\n" << "%local_texCoord_xy = OpCompositeConstruct %type_vec2 %local_texCoord_x %local_texCoord_y\n" << "%local_texCoord_xyz = OpCompositeConstruct %type_vec3 %local_texCoord_x %local_texCoord_y %local_texCoord_z\n" << "%access_uniformblock_member_uint_lod = OpAccessChain %type_pushconstant_uniformblock_member_lod %uniformblock_instance %constant_int_0\n" << "%local_uniformblock_member_uint_lod = OpLoad %type_uint %access_uniformblock_member_uint_lod\n" << "%local_uniformblock_member_float_lod = OpConvertUToF %type_float %local_uniformblock_member_uint_lod\n" << "%access_uniformblock_member_size = OpAccessChain %type_pushconstant_uniformblock_member_size %uniformblock_instance %constant_int_1\n" << "%local_uniformblock_member_size = OpLoad %type_vec2 %access_uniformblock_member_size\n" << sparseImageOpString("%local_sparse_op_result", "%type_struct_int_img_comp_vec4", "%local_image_sparse", coordString, "%local_uniformblock_member_float_lod") << "\n" // Load texel value << "%local_img_comp_vec4 = OpCompositeExtract " << typeImgCompVec4 << " %local_sparse_op_result 1\n" << "OpStore %output_texel %local_img_comp_vec4\n" // Load residency code << "%local_residency_code = OpCompositeExtract %type_int %local_sparse_op_result 0\n" // Check if loaded texel is placed in resident memory << "%local_texel_resident = OpImageSparseTexelsResident %type_bool %local_residency_code\n" << "OpSelectionMerge %branch_texel_resident None\n" << "OpBranchConditional %local_texel_resident %label_texel_resident %label_texel_not_resident\n" << "%label_texel_resident = OpLabel\n" // Loaded texel is in resident memory << "OpStore %output_residency %constant_texel_resident\n" << "OpBranch %branch_texel_resident\n" << "%label_texel_not_resident = OpLabel\n" // Loaded texel is not in resident memory << "OpStore %output_residency %constant_texel_not_resident\n" << "OpBranch %branch_texel_resident\n" << "%branch_texel_resident = OpLabel\n" << "OpReturn\n" << "OpFunctionEnd\n"; programCollection.spirvAsmSources.add("fragment_shader") << fs.str(); }
void SDL_TMXMap::Populate_Map(SDL_Renderer *Render) { if( MapSurf || getMapFile().length()) { if (!MapSurf) { std::ifstream *in_xml = new ifstream(getMapFile().c_str(), ifstream::in); if(!in_xml->is_open()) { std::cout << "No way to Populate Map. Quitting..." <<endl; return; } std::stringstream *ss_xml = new std::stringstream; *ss_xml << in_xml->rdbuf(); char *xml_data = new char[ss_xml->str().length()+1](); strcpy(xml_data, ss_xml->str().c_str()); in_xml->close(); delete ss_xml; Load_Map(xml_data); MapSurf = SDL_CreateRGBSurface(0, getWidth()*getTileWidth(), getHeight()*getTileHeight(), 32, rmask, gmask, bmask, amask); } string ResDir = "Resources\\"; SDL_Surface **TileSurf = new SDL_Surface*[getNumTilesets()]; for ( unsigned int fn = 0; fn < getNumTilesets(); fn++) { //eventually, there will be a means to load multiple images per tileset. TODO: Make a loop that allows it. //TODO: Write it so that it also works with string Filenname = ResDir + getTileset(fn).getImage(0).getFilename(); TileSurf[fn] = IMG_Load(Filenname.c_str()); if (!TileSurf[fn]) return; } unsigned long color = getTileset(0).getImage(0).getTrans(); SDL_Color CKey; CKey.r = (color & 0xFF0000) >> 16; CKey.g = (color & 0x00FF00) >> 8 ; CKey.b = (color & 0x0000FF) ; SDL_SetColorKey( MapSurf , SDL_TRUE , SDL_MapRGB(TileSurf[0]->format , CKey.r , CKey.g , CKey.b)); SDL_Rect SrcRect; SDL_Rect DstRect; DstRect.h = getTileHeight(); DstRect.w = getTileWidth(); unsigned char **in_data = new unsigned char* [getNumLayers()]; unsigned char **out_data = new unsigned char* [getNumLayers()]; unsigned int **tiledata = (unsigned int **) out_data; for(unsigned i = 0; i < getNumLayers(); i++) { in_data[i] = new unsigned char [getLayer(i).getData().getData().size()]; out_data[i] = new unsigned char [getWidth()*getHeight()*4]; memcpy( in_data[i] , getLayer(i).getData().getData().c_str() , getLayer(i).getData().getData().size() ); unsigned char *dec_data = new unsigned char[( getLayer(i).getData().getData().size())]; TMX_Decode( in_data[i] , dec_data , getLayer(i).getData().getData().size() ); TMX_Uncompress( dec_data , out_data[i] , ( getLayer(i).getData().getData().size() ), getWidth() * getHeight() * 4, getLayer(i).getData().getCompression().c_str()); } delete[]in_data; for (unsigned l = 0; l < TMX_Map::getNumLayers(); l++) { LayerSurf.push_back(SDL_CreateRGBSurface(0, getWidth()*getTileWidth(), getHeight()*getTileHeight(), 32, rmask, gmask, bmask, amask)); SDL_SetSurfaceAlphaMod(LayerSurf[l], getLayer(l).getOpacity() * 255); for(unsigned int y = 0; y < getHeight(); y++) { DstRect.y = y * getTileHeight(); for (unsigned int x = 0; x < getWidth(); x++) { if(tiledata[l][y*getWidth()+x]) { DstRect.x = x * getTileWidth(); unsigned tilesetindex = findTileset(tiledata[l][y*getWidth()+x]); unsigned srcindex = tiledata[l][y*getWidth()+x] - getTileset(tilesetindex).getGID(); SrcRect.h = getTileset(tilesetindex).getTileHeight(); SrcRect.w = getTileset(tilesetindex).getTileWidth(); float Float_TPL = (float) getTileset(tilesetindex).getImage(0).getWidth() / (getTileset(tilesetindex).getTileWidth() + getTileset(tilesetindex).getSpacing()); unsigned long Tiles_Per_Line = (long) ceil(Float_TPL); SrcRect.x = srcindex % Tiles_Per_Line * (getTileset(tilesetindex).getTileWidth() + getTileset(tilesetindex).getSpacing()); SrcRect.y = srcindex / Tiles_Per_Line * (getTileset(tilesetindex).getTileWidth() + getTileset(tilesetindex).getSpacing()); if( SDL_BlitSurface(TileSurf[tilesetindex], &SrcRect, LayerSurf[l], &DstRect) ) { cout << "SDL_BlitSurface Failed: " << SDL_GetError() << endl; // if for some reason the application does not implode and instead run this code, we need to know why it crapped us. exit (-2); } } } } if(getLayer(l).isVisible()) SDL_BlitSurface(LayerSurf[l],NULL, MapSurf, NULL); } delete[] tiledata; for (unsigned l = 0; l < getNumTilesets(); l++) SDL_FreeSurface(TileSurf[l]); MapTex = SDL_CreateTextureFromSurface(Render, MapSurf); SDL_FreeSurface(MapSurf); } else std::cout << "No way to Populate Map. Quitting..." << endl;