void TextureSequenceOptimizer::saveMax( fs::path path )
{
    if ( path == fs::path() ) {
        path = app::App::get()->getFolderPath();
        app::console() << "SAVE MAX: " << path << std::endl;
    }
    if( ! path.empty() ){
        
        fs::path jsonPath = path;
        jsonPath.append("sequence.json");
        JsonTree doc = JsonTree::makeObject();
        
        JsonTree size = JsonTree::makeObject("size");
        size.pushBack(JsonTree("width",  mOriOutline.getWidth()  ));
        size.pushBack(JsonTree("height", mOriOutline.getHeight() ));
        doc.pushBack(size);
        
        JsonTree sequence = JsonTree::makeArray("sequence");
        //go thru each surface
        for (int i = 0; i < mSurfaceRefs.size(); i++) {
            fs::path tempPath = path;
            
            //only clone the non-transparent area based on the offsets
            Surface tempSurf;
            JsonTree curImage = JsonTree::makeObject();
            
            if( mTrimMaxAreas[i].calcArea() == 0 ){
                app::console() << " Image is completely transparent: " << mFileNames[i] << std::endl;
                tempPath.append("transparent.png");
                
                // check if transparent pixel exists
                if( !fs::exists(tempPath) ){
                    // create transparent png if it doesn't exist
                    tempSurf = mSurfaceRefs[i]->clone( Area(0,0,10,10) );
                    writeImage( tempPath, tempSurf );
                }
                
                // point to transparent image
                curImage.pushBack(JsonTree("x", mTrimMaxAreas[i].x1));
                curImage.pushBack(JsonTree("y", mTrimMaxAreas[i].y1));
                curImage.pushBack(JsonTree("fileName", "transparent.png" ));
            }else{
                tempSurf = mSurfaceRefs[i]->clone(mTrimMaxAreas[i]);
                tempPath.append(toString(mFileNames[i]));
                writeImage( tempPath, tempSurf );
                curImage.pushBack(JsonTree("x", mTrimMaxAreas[i].x1));
                curImage.pushBack(JsonTree("y", mTrimMaxAreas[i].y1));
                curImage.pushBack(JsonTree("fileName", mFileNames[i] ));
            }
            sequence.pushBack(curImage);
            
            //app::console() << "saving: " << tempPath << " "<< mTrimMaxAreas[i] << std::endl;
            
            tempPath.clear();
        }
        doc.pushBack(sequence);
        doc.write( jsonPath, JsonTree::WriteOptions());
        //saveJson(path);
    }
}
Exemplo n.º 2
0
	void PretzelGlobal::saveSettings(fs::path settingsPath){
		fs::path appPath = settingsPath;

		if (appPath.string() == ""){
			appPath = getAppPath() / "guiSettings";
			if (!fs::exists(appPath)){
				console() << appPath << " does not exist" << endl;
				fs::create_directory(appPath);
			}
			appPath /= "settings.json";
		}

		JsonTree pSettings = JsonTree::makeObject( "pretzelSettings" );
		std::string tmp;
		for (int i = 0; i < mParamList.size(); i++){
			switch (mParamList[i].type){
			case _FLOAT:
				pSettings.pushBack( JsonTree(mParamList[i].name, to_string(*(float*)mParamList[i].value)) );
				break;
			case _INT:
				pSettings.pushBack(JsonTree(mParamList[i].name, to_string(*(int*)mParamList[i].value)));
				break;
			case _BOOL:
				tmp = ((*(bool*)mParamList[i].value) == true) ? "1" : "0";
				pSettings.pushBack(JsonTree(mParamList[i].name, tmp));
				break;
			default:
				break;
			}
		}

		JsonTree root;
		root.pushBack(pSettings);
		root.write(appPath, JsonTree::WriteOptions());
	}
Exemplo n.º 3
0
void Param::save() {
  JsonTree Position;
  Position = JsonTree::makeObject("Position");
  Position.addChild(JsonTree("x", pos.x));
  Position.addChild(JsonTree("y", pos.y));
  Position.addChild(JsonTree("z", pos.z));
  
  JsonTree Size;
  Size = JsonTree::makeObject("Size");
  Size.addChild(JsonTree("x", size.x));
  Size.addChild(JsonTree("y", size.y));
  Size.addChild(JsonTree("z", size.z));
  
  JsonTree Color;
  Color = JsonTree::makeObject("Color");
  Color.addChild(JsonTree("r", color.r));
  Color.addChild(JsonTree("g", color.g));
  Color.addChild(JsonTree("b", color.b));
  Color.addChild(JsonTree("a", color.a));
  
  JsonTree data;
  data = JsonTree::makeObject(name);
  data.addChild(Position);
  data.addChild(Size);
  data.addChild(Color);
  
  data.write(getAppPath() / "../../../../assets/player.json", JsonTree::WriteOptions().createDocument(true));
}
Exemplo n.º 4
0
void FaceController::saveFace()
{/*
 for (size_t i = 0, ilen= facesStoreVector.size(); i<ilen; i++)
	{
		JsonTree oneFaceJson;
		oneFaceJson.addChild( JsonTree( "texname", facesStoreVector[i].getTexName() ) );

		JsonTree facesDataJson = JsonTree::makeArray( "data" );

		auto points =  facesStoreVector[i].getPoints();
		for (size_t j = 0, ilen = points.size() ; j < ilen; j++)
		{
			JsonTree point;
			point.addChild(JsonTree( "x",points[j].x) );	
			point.addChild(JsonTree( "y",points[j].y) );	
			facesDataJson.pushBack(point);
		}
		oneFaceJson.addChild(facesDataJson );

		facesJson.pushBack(oneFaceJson);
	}

	doc.pushBack( facesJson );
	
	writeImage( getAppPath() /FACE_STORAGE_FOLDER/genericName, surf );
	doc.write( writeFile( getAppPath() / DATA_BASE_NAME ), JsonTree::WriteOptions() );	*/

	// SAVE LAST ONLY!!!!


	JsonTree doc;
	JsonTree facesJson = JsonTree::makeArray( "faces" );

	int id = facesStoreVector.size() - 1;

	JsonTree oneFaceJson;
	oneFaceJson.addChild( JsonTree( "texname", facesStoreVector[id].getTexName() ) );

	JsonTree facesDataJson = JsonTree::makeArray( "data" );

		auto points =  facesStoreVector[id].getPoints();
		for (size_t j = 0, ilen = points.size() ; j < ilen; j++)
		{
			JsonTree point;
			point.addChild(JsonTree( "x",points[j].x) );	
			point.addChild(JsonTree( "y",points[j].y) );	
			facesDataJson.pushBack(point);
		}
	oneFaceJson.addChild(facesDataJson );
	facesJson.pushBack(oneFaceJson);

	doc.pushBack( facesJson );

	string jsonName = "base_"+to_string(id) + ".json";	
	
	
	doc.write( writeFile( getAppPath() / JSON_STORAGE_FOLDER / jsonName ), JsonTree::WriteOptions() );

}
Exemplo n.º 5
0
void ForestApp::writeButton()
{
    // Exits the simulation thread at the next chance we get

    JsonTree root = JsonTree::makeObject();

    mSimMutex.lock();
    root.addChild(mPanels.serialize());
    root.addChild(mDots.serialize());
    root.addChild(mStrandBox.serialize());
    mSimMutex.unlock();

    root.write(getSaveFilePath("growth.json"));
}
Exemplo n.º 6
0
void JsonBag::save() const
{
	CI_ASSERT( fs::is_regular_file( mJsonFilePath ) );

	JsonTree doc;
	for( auto& group : mItems ) {
		JsonTree jsonGroup = JsonTree::makeArray( group.first );
		for( const auto& item : group.second ) {
			item.second->save( item.first, &jsonGroup );
		}
		doc.pushBack( jsonGroup );
	}
	doc.addChild( JsonTree{ "version", mVersion } );
	doc.write( writeFile( mJsonFilePath ), JsonTree::WriteOptions() );
}
void TextureSequenceOptimizer::saveJson( const fs::path& path )
{
    fs::path jsonPath = path;
    jsonPath.append("sequence.json");
    
    //save the offsets for each image into a json file
    JsonTree doc = JsonTree::makeObject();
    
    JsonTree size = JsonTree::makeObject();
    size.pushBack(JsonTree("width",  mOriOutline.getWidth()  ));
    size.pushBack(JsonTree("height", mOriOutline.getHeight() ));
    doc.pushBack(size);
    
    JsonTree sequence = JsonTree::makeArray("sequence");
    for (int i = 0; i < mTrimMaxAreas.size(); i ++) {
        JsonTree curImage = JsonTree::makeObject();
        curImage.pushBack(JsonTree("x", mTrimMaxAreas[i].x1));
        curImage.pushBack(JsonTree("y", mTrimMaxAreas[i].y1));
        curImage.pushBack(JsonTree("fileName", mFileNames[i] ));
        sequence.pushBack(curImage);
    }
    doc.pushBack(sequence);
    doc.write( jsonPath, JsonTree::WriteOptions());
}
Exemplo n.º 8
0
	void PretzelGlobal::saveSettings(fs::path settingsPath){
		fs::path appPath = settingsPath;

		if (appPath.string() == ""){
			appPath = getAppPath() / "guiSettings";

			if (!fs::exists(appPath)){
				CI_LOG_W( "Pretzel :: " ) << appPath << " does not exist. Creating it.";
				fs::create_directory(appPath);
			}
			appPath /= "settings.json";
		}

		JsonTree pSettings = JsonTree::makeObject("pretzelSettings");
		std::string tmp;
		for (int i = 0; i < mParamList.size(); i++){
			switch (mParamList[i].type){
                case _FLOAT:{
                    pSettings.pushBack(JsonTree(mParamList[i].name, toString(*(float*)mParamList[i].value)));
                    break;
                }case _INT:{
                    pSettings.pushBack(JsonTree(mParamList[i].name, toString(*(int*)mParamList[i].value)));
                    break;
                }case _BOOL:{
                    tmp = ((*(bool*)mParamList[i].value) == true) ? "1" : "0";
                    pSettings.pushBack(JsonTree(mParamList[i].name, tmp));
                    break;
                }case _STRING:{
                    pSettings.pushBack(JsonTree(mParamList[i].name, (*(std::string*)mParamList[i].value)));
                    break;
                }case _VEC2:{
                    JsonTree tt;
                    tt = tt.makeArray(mParamList[i].name);
                    tt.pushBack( JsonTree("x", toString(((vec2*)mParamList[i].value)->x)) );
                    tt.pushBack( JsonTree("y", toString(((vec2*)mParamList[i].value)->y)) );
                    pSettings.pushBack( tt );
                    break;
                }case _VEC3:{
                    JsonTree tt;
                    tt = tt.makeArray(mParamList[i].name);
                    tt.pushBack( JsonTree("x", toString(((vec3*)mParamList[i].value)->x)) );
                    tt.pushBack( JsonTree("y", toString(((vec3*)mParamList[i].value)->y)) );
                    tt.pushBack( JsonTree("z", toString(((vec3*)mParamList[i].value)->z)) );
                    pSettings.pushBack( tt );
                    break;
                }case _COLOR:{
                    JsonTree tt;
                    tt = tt.makeArray(mParamList[i].name);
                    tt.pushBack( JsonTree("r", toString(((Color*)mParamList[i].value)->r)) );
                    tt.pushBack( JsonTree("g", toString(((Color*)mParamList[i].value)->g)) );
                    tt.pushBack( JsonTree("b", toString(((Color*)mParamList[i].value)->b)) );
                    pSettings.pushBack( tt );
                    break;
                }case _COLORA:{
                    JsonTree tt;
                    tt = tt.makeArray(mParamList[i].name);
                    tt.pushBack( JsonTree("r", toString(((ColorA*)mParamList[i].value)->r)) );
                    tt.pushBack( JsonTree("g", toString(((ColorA*)mParamList[i].value)->g)) );
                    tt.pushBack( JsonTree("b", toString(((ColorA*)mParamList[i].value)->b)) );
                    tt.pushBack( JsonTree("a", toString(((ColorA*)mParamList[i].value)->a)) );
                    pSettings.pushBack( tt );
                    break;
                }default: {
                    break;
                }
			}
		}

		JsonTree root;
		root.pushBack(pSettings);
		root.write(appPath, JsonTree::WriteOptions());
        
        signalOnSettingsSave.emit();
	}
Exemplo n.º 9
0
void JsonTestApp::mouseDown( MouseEvent event )
{

    JsonTree doc;
    JsonTree library = JsonTree::makeObject( "library" );
    JsonTree album = JsonTree::makeArray( "album" );

    album.pushBack( JsonTree( "musician", string( "Sufjan Stevens" ) ) );
    album.pushBack( JsonTree( "year", string( "2004" ) ) );
    album.pushBack( JsonTree( "title", string( "Seven Swans" ) ) );

    JsonTree tracks = JsonTree::makeArray( "tracks" );

    for ( int32_t i = 0; i < 6; i ++ ) {

        JsonTree track;
        track.pushBack( JsonTree( "id", i + 1 ) );

        JsonTree title;
        switch ( i ) {
        case 0:
            title = JsonTree( "title", "All the Trees of the Field Will Clap Their Hands" );
            break;
        case 1:
            title = JsonTree( "title", "The Dress Looks Nice on You" );
            break;
        case 2:
            title = JsonTree( "title", "In the Dev Hole's Territory" );
            break;
        case 3:
            title = JsonTree( "title", "To Be a Clone With You" );
            break;
        case 4:
            title = JsonTree( "title", "To Be Removed" );
            break;
        case 5:
            title = JsonTree( "title", "To Be Removed" );
            break;
        }

        track.pushBack( title );
        tracks.pushBack( track );

    }

    for ( JsonTree::Iter trackIt = tracks.begin(); trackIt != tracks.end(); ++trackIt ) {
        if ( trackIt->getChild( "id" ).getValue<int>() == 3 ) {
            JsonTree track;
            track.pushBack( JsonTree( "id", 3 ) );
            track.pushBack( JsonTree( "title", "In the Devil's Territory" ) );
            tracks.replaceChild( trackIt, track );
        }
    }

    JsonTree track;
    track.pushBack( JsonTree( "id", 4 ) );
    track.pushBack( JsonTree( "title", "To Be Alone With You" ) );
    tracks.replaceChild( 3, track );

    tracks.removeChild( 4 );

    for ( JsonTree::Iter trackIt = tracks.begin(); trackIt != tracks.end(); ) {
        if ( trackIt->getChild( "id" ).getValue<int>() == 6 ) {
            trackIt = tracks.removeChild( trackIt );
        } else {
            ++trackIt;
        }
    }

    album.pushBack( tracks );
    library.pushBack( album );
    doc.pushBack( library );

    console() << doc;

    doc.write( writeFile( getDocumentsDirectory() + "testoutput.json" ), false );

}