示例#1
0
void
xfel::parameter::organizer_base::initialize_gradients_curvatures(){
  typedef std::map<std::string,parameter_array>::iterator iter;
  for (iter M = _P.begin(); M != _P.end(); ++M){
    if (M->second.local_flag) {continue;}
    M->second.gradients = farray(M->second.parameters.size());
    M->second.curvatures = farray(M->second.parameters.size());
  }
}
void templateClassDemo()
{
    unsigned i;

    /* We will create two arrays using template class "Array".
     * The first array will be an integer and the second array
     * will be a floating point array. Please step through the
     * next two lines to see how this is done.
     */
    Array<int>      iarray(10);
    Array<float>    farray(20);

    /* To see how the template class is initialized, please step through
     * the following two loops. The first loop will initialize the
     * array of integers and the second loop will initialize the array
     * of floating point numbers.
     */
    for (i = 0; i < iarray.getSize(); i++)
    {
        iarray[i] = i;
    }

    float f = 0.0f;
    for (i = 0; i < farray.getSize(); i++)
    {
        farray[i] = f;
        f += (float)1.1;
    }
}
示例#3
0
double
xfel_legacy::algorithm::mark5_iteration::compute_functional_only(
    farray tox, farray toy, farray spotcx, farray spotcy,
    farray spotfx, farray spotfy,
    iarray master_tiles,iarray frames,
    vec3array partial_r_partial_distance){

    model_calcx=farray(spotcx.size(),scitbx::af::init_functor_null<double>());
    model_calcy=farray(spotcx.size(),scitbx::af::init_functor_null<double>());

    int ntiles = _P["tile_trans"].ndata;
    SCITBX_ASSERT(tox.size()==ntiles);
    SCITBX_ASSERT(toy.size()==ntiles);

    functional = 0.;
    sine = std::vector<double>();
    cosine = std::vector<double>();
    farray rotations = _P["tile_rot"].parameters;
    for (int tidx=0; tidx < ntiles; ++tidx){
      cosine.push_back(std::cos(rotations[tidx]*scitbx::constants::pi_180));
      sine.push_back(std::sin(rotations[tidx]*scitbx::constants::pi_180));
    }

    const double* translations    = &(_P["tile_trans"].parameters.const_ref()[0]);

    for (int ridx=0; ridx < spotcx.size(); ++ridx){
      int itile = master_tiles[ridx];

      calc_minus_To_x = spotcx[ridx] - tox[itile];
      calc_minus_To_y = spotcy[ridx] - toy[itile];

      rotated_o_x = calc_minus_To_x * cosine[itile]
                  - calc_minus_To_y * sine[itile];
      rotated_o_y = calc_minus_To_x * sine[itile]
                  + calc_minus_To_y * cosine[itile];

      model_calcx[ridx] = rotated_o_x + (tox[itile] + translations[2*itile]);
      model_calcy[ridx] = rotated_o_y + (toy[itile] + translations[2*itile+1]);

      double delx = model_calcx[ridx] - spotfx[ridx];
      double dely = model_calcy[ridx] - spotfy[ridx];
      double delrsq(delx*delx + dely*dely);
      functional += delrsq; // sum of square differences
    }
    return functional;
}
示例#4
0
void GameData::writeQuestData()
{
	//write json
	rapidjson::Document document;
	document.SetArray();
	rapidjson::Document::AllocatorType& allocator = document.GetAllocator();
	rapidjson::Value str;
	for (auto& i : m_mapQuestsData)
	{
		auto second = i.second;
		rapidjson::Value object(rapidjson::kObjectType);
		object.AddMember("id", second->id, allocator);

		object.AddMember("level", second->level, allocator);

		str.SetString(second->title.c_str(), second->title.length(), allocator);
		object.AddMember("title", str, allocator);

		str.SetString(second->instruct.c_str(), second->instruct.length(), allocator);
		object.AddMember("instruct", str, allocator);

		object.AddMember("status", second->status, allocator);

		str.SetString(second->targetNpc.c_str(), second->targetNpc.length(), allocator);
		object.AddMember("targetNpc", str, allocator);

		str.SetString(second->launchNpc.c_str(), second->launchNpc.length(), allocator);
		object.AddMember("launchNpc", str, allocator);

		rapidjson::Value farray(rapidjson::kArrayType);
		for (auto& j : second->forgeID) {
			rapidjson::Value object(rapidjson::kObjectType);
			object.SetInt(j);
			farray.PushBack(object, allocator);
		}
		object.AddMember("forgeID", farray, allocator);

		rapidjson::Value marray(rapidjson::kArrayType);
		for (auto& j : second->mons_id) {
			rapidjson::Value object(rapidjson::kObjectType);
			object.SetInt(j);
			marray.PushBack(object, allocator);
		}
		object.AddMember("mons_id", marray, allocator);

		object.AddMember("mapID", second->mapID, allocator);

		object.AddMember("type", second->type, allocator);
		document.PushBack(object, allocator);
	}
	rapidjson::StringBuffer buffer;
	rapidjson::Writer<rapidjson::StringBuffer> writer(buffer);
	document.Accept(writer);
	auto out = buffer.GetString();
	ofstream fp(QUESTSAVE_DATA_PATH, ios_base::out);
	fp << out;
}
int main() {
	int a[3];
	a[-1] = farray(a, a[6]);
	return 0;
}
示例#6
0
MStatus ProxyViz::compute( const MPlug& plug, MDataBlock& block )
{
	if(!m_enableCompute) return MS::kSuccess;
	if( plug == outValue ) {
		
		updateWorldSpace(thisMObject() );
		
		MStatus status;

		ExampVox * defBox = plantExample(0);
		
		defBox->setGeomSizeMult(block.inputValue(aradiusMult).asFloat() );
		
		defBox->setGeomBox(block.inputValue(abboxminx).asFloat(),
			block.inputValue(abboxminy).asFloat(), 
			block.inputValue(abboxminz).asFloat(), 
			block.inputValue(abboxmaxx).asFloat(), 
			block.inputValue(abboxmaxy).asFloat(), 
			block.inputValue(abboxmaxz).asFloat());
		
		float grdsz = defBox->geomExtent() * 32.f ;
		if(grdsz < 32.f) {
			AHelper::Info<float>(" ProxyViz input box is too small", grdsz);
			grdsz = 32.f;
			AHelper::Info<float>(" trancated to", grdsz);
		}
		
		if(m_toSetGrid) {
			m_toSetGrid = false;
			resetGrid(grdsz);
		}
		
		if(_firstLoad) {
/// internal cache only, initializing from external cache is obsolete 
			if(!loadInternal(block) )
				std::cout<<"\n ERROR proxviz cannot load internal cache";

			_firstLoad = 0;
		}
        
		if(!m_toCheckVisibility) {
			MArrayDataHandle groundMeshArray = block.inputArrayValue(agroundMesh );
			MArrayDataHandle groundSpaceArray = block.inputArrayValue(agroundSpace );
/// in case no ground is connected
            if(updateGround(groundMeshArray, groundSpaceArray )) {
                moveWithGround();
                AHelper::Info<std::string>(" ProxyViz ground ", groundBuildLog() );
            }
		}
		
		if(!m_hasParticle) {
			block.setClean(plug);
            return MS::kSuccess;
		}
		
		const int ngroups = block.inputValue(agroupcount).asInt();
		
		MDataHandle hdata = block.inputValue(outPositionPP, &status);
        MFnVectorArrayData farray(hdata.data(), &status);
        if(!status) {
            MGlobal::displayInfo("proxy viz is not properly connected to a particle system");
			block.setClean(plug);
            return MS::kSuccess;
        }
    
        MDataHandle scaledata = block.inputValue(outScalePP, &status);
        MFnVectorArrayData scalearray(scaledata.data(), &status);
        if(!status) {
            MGlobal::displayInfo("proxy viz is not properly connected to a particle system");
			block.setClean(plug);
            return MS::kSuccess;
        }
		
		MDataHandle rotatedata = block.inputValue(outRotationPP, &status);
        MFnVectorArrayData rotatearray(rotatedata.data(), &status);
        if(!status) {
            MGlobal::displayInfo("proxy viz is not properly connected to a particle system");
			block.setClean(plug);
            return MS::kSuccess;
        }
		
		MDataHandle replaceData = block.inputValue(outReplacePP, &status);
        MFnDoubleArrayData replaceArrayFn(replaceData.data(), &status);
        if(!status) {
            MGlobal::displayInfo("proxy viz is not properly connected to a particle system, needs userScalarPP");
			block.setClean(plug);
            return MS::kSuccess;
        }
		
		MVectorArray outPosArray = farray.array();	
        MVectorArray outScaleArray = scalearray.array();
		MVectorArray outRotateArray = rotatearray.array();
		MDoubleArray outReplaceArray = replaceArrayFn.array();
		
		if( outPosArray.length() < 1) {
			block.setClean(plug);
			return MS::kSuccess;
		}
		
		computePPAttribs(outPosArray, outRotateArray, outScaleArray, outReplaceArray,
						ngroups);

        float result = outPosArray.length();

		MDataHandle outputHandle = block.outputValue( outValue );
		outputHandle.set( result );
		block.setClean(plug);
    }
	if(plug == outValue1) {
		
		MArrayDataHandle hArray = block.inputArrayValue(ainexamp);
		updateExamples(hArray);

		float result = 91.f;

		MDataHandle outputHandle = block.outputValue( outValue1 );
		outputHandle.set( result );
		block.setClean(plug);
	}

	return MS::kSuccess;
}
示例#7
0
double
xfel_legacy::algorithm::mark5_iteration::compute_target(
    farray tox, farray toy, farray spotcx, farray spotcy,
    farray spotfx, farray spotfy,
    iarray master_tiles,iarray frames,
    vec3array partial_r_partial_distance){

    model_calcx=farray(spotcx.size(),scitbx::af::init_functor_null<double>());
    model_calcy=farray(spotcx.size(),scitbx::af::init_functor_null<double>());

    int ntiles = _P["tile_trans"].ndata;
    SCITBX_ASSERT(tox.size()==ntiles);
    SCITBX_ASSERT(toy.size()==ntiles);

    functional = 0.;
    sine = std::vector<double>();
    cosine = std::vector<double>();
    farray rotations = _P["tile_rot"].parameters;
    for (int tidx=0; tidx < ntiles; ++tidx){
      cosine.push_back(std::cos(rotations[tidx]*scitbx::constants::pi_180));
      sine.push_back(std::sin(rotations[tidx]*scitbx::constants::pi_180));
    }

    const double* translations    = &(_P["tile_trans"].parameters.const_ref()[0]);
    double* translation_gradients = &(_P["tile_trans"].gradients.ref()[0]);
    double* rotation_gradients    = &(_P["tile_rot"].gradients.ref()[0]);
    double* frame_trans_gradients = &(_P["frame_trans"].gradients.ref()[0]);
    double* frame_dist_gradients  = &(_P["frame_distance"].gradients.ref()[0]);
    double* tile_dist_gradients   = &(_P["tile_distance"].gradients.ref()[0]);
    double* frame_rotz_gradients  = &(_P["frame_rotz"].gradients.ref()[0]);
    double* half_mos_gradients    = &(_P["half_mosaicity_rad"].gradients.ref()[0]);
    double* translation_curvatures= &(_P["tile_trans"].curvatures.ref()[0]);
    double* rotation_curvatures   = &(_P["tile_rot"].curvatures.ref()[0]);
    double* frame_trans_curvatures= &(_P["frame_trans"].curvatures.ref()[0]);
    double* frame_dist_curvatures = &(_P["frame_distance"].curvatures.ref()[0]);
    double* tile_dist_curvatures  = &(_P["tile_distance"].curvatures.ref()[0]);
    double* frame_rotz_curvatures = &(_P["frame_rotz"].curvatures.ref()[0]);
    double* half_mos_curvatures   = &(_P["half_mosaicity_rad"].curvatures.ref()[0]);

    int nframes = _P["frame_trans"].ndata;
    for (int ridx=0; ridx < spotcx.size(); ++ridx){
      int itile = master_tiles[ridx];
      int frame_param_no = frames[ridx];
      /*printf("ridx %5d frame %5d  partmos %8.5f %8.5f %8.5f \n",ridx, frame_param_no,
        vecc._V["half_mosaicity_rad"].gradients[ridx][0],
        vecc._V["half_mosaicity_rad"].gradients[ridx][1],
        vecc._V["half_mosaicity_rad"].gradients[ridx][2]

        );
      */
      calc_minus_To_x = spotcx[ridx] - tox[itile];
      calc_minus_To_y = spotcy[ridx] - toy[itile];

      rotated_o_x = calc_minus_To_x * cosine[itile]
                  - calc_minus_To_y * sine[itile];
      rotated_o_y = calc_minus_To_x * sine[itile]
                  + calc_minus_To_y * cosine[itile];

      model_calcx[ridx] = rotated_o_x + (tox[itile] + translations[2*itile]);
      model_calcy[ridx] = rotated_o_y + (toy[itile] + translations[2*itile+1]);

      partial_partial_theta_x = -calc_minus_To_x * sine[itile]
                               - calc_minus_To_y * cosine[itile];
      partial_partial_theta_y =  calc_minus_To_x * cosine[itile]
                               - calc_minus_To_y * sine[itile];

      partial_sq_theta_x = -calc_minus_To_x * cosine[itile]
                          + calc_minus_To_y * sine[itile];
      partial_sq_theta_y = -calc_minus_To_x * sine[itile]
                          - calc_minus_To_y * cosine[itile];

      double delx = model_calcx[ridx] - spotfx[ridx];
      double dely = model_calcy[ridx] - spotfy[ridx];
      double delrsq(delx*delx + dely*dely);
      functional += delrsq; // sum of square differences

      vec3 part_r_part_d = partial_r_partial_distance[ridx];
      double rotated_part_r_c_x = part_r_part_d[0] * cosine[itile]
                                - part_r_part_d[1] * sine[itile];
      double rotated_part_r_c_y = part_r_part_d[0] * sine[itile]
                                + part_r_part_d[1] * cosine[itile];

      translation_gradients[2*itile]  += 2. *  delx;
      translation_gradients[2*itile+1]+= 2. *  dely;

      if (frame_param_no < nframes){
        frame_trans_gradients[2*frame_param_no]  += 2. *  delx;
        frame_trans_gradients[2*frame_param_no+1]+= 2. *  dely;
        frame_dist_gradients[frame_param_no] += 2. * (
          delx * rotated_part_r_c_y + dely * rotated_part_r_c_x
        );//  SOMETHING IS ROTTEN IN DENMARK
      }
      //tile_dist_gradients[itile/2] += 2.*(delx * rotated_part_r_c_y + dely * rotated_part_r_c_x);

      rotation_gradients[itile] += scitbx::constants::pi_180 * 2.* (
        delx * partial_partial_theta_x +
        dely * partial_partial_theta_y
      );

      translation_curvatures[2*itile] += 2.;
      translation_curvatures[2*itile+1] += 2.;
      if (frame_param_no < nframes){
        frame_trans_curvatures[2*frame_param_no] += 2.;
        frame_trans_curvatures[1+2*frame_param_no] += 2.;
        frame_dist_curvatures[frame_param_no] +=2 * (
          rotated_part_r_c_x * rotated_part_r_c_x
        + rotated_part_r_c_y * rotated_part_r_c_y
        );
      }
      //tile_dist_curvatures[itile/2] += 2 * (
      //rotated_part_r_c_x * rotated_part_r_c_x + rotated_part_r_c_y * rotated_part_r_c_y);

      rotation_curvatures[itile] += scitbx::constants::pi_180 *
                                    scitbx::constants::pi_180 * 2. * (
        ( partial_partial_theta_x*partial_partial_theta_x +
          partial_partial_theta_y*partial_partial_theta_y ) +
        ( delx*partial_sq_theta_x + dely*partial_sq_theta_y )
      );

      // XXX make this map lookup more efficient
      if (_P["frame_rotz"].size()>0 && frame_param_no < nframes){
        //rotz angle is in radians; no need for pi_180 prefactor
        double origin_x = frame_origins[frame_param_no][0];
        double origin_y = frame_origins[frame_param_no][1];
        //
        double d_rcth_d_th_x = -(model_calcy[ridx] - origin_y);
        double d_rcth_d_th_y =   model_calcx[ridx] - origin_x;
        frame_rotz_gradients[frame_param_no] += 2. * (
          delx * d_rcth_d_th_x + dely * d_rcth_d_th_y );

        frame_rotz_curvatures[frame_param_no] += 2. * (
          ( delx * (-d_rcth_d_th_y) + dely * d_rcth_d_th_x) +
          ( d_rcth_d_th_x * d_rcth_d_th_x + d_rcth_d_th_y * d_rcth_d_th_y)
        );

      }

      if ( !_P["half_mosaicity_rad"].local_flag && _P["half_mosaicity_rad"].size()>0 &&
          frame_param_no < nframes){
        half_mos_gradients[frame_param_no] += 2. * (
          delx * vecc._V["half_mosaicity_rad"].gradients[ridx][1] +
          dely * vecc._V["half_mosaicity_rad"].gradients[ridx][0] );
          //  SOMETHING IS ROTTEN IN DENMARK (swap x & y for correct derivative)

        //first order approximation to curvature suggested by David Waterman
        half_mos_curvatures[frame_param_no] += 2. * (
          vecc._V["half_mosaicity_rad"].gradients[ridx].length_sq() // v.v dot product

          //These two lines are probably wrong.  Switch 0 & 1? vecc._V source incorrect?
          + (delx * vecc._V["half_mosaicity_rad"].curvatures[ridx][1])
          + (dely * vecc._V["half_mosaicity_rad"].curvatures[ridx][0])
        );

      }
    }
    return functional;
}