コード例 #1
0
void RemoteServerProxyUpdater::run() {
  while (keep_going_) {
    try {
      MessageReader reader(socket_);
      Message *message = reader.read_message();  // Need a pointer because of polymorphism
      if (message->type() == GameInitMessage::type_id()) {
        handle_objects(dynamic_cast<GameInitMessage *>(message));
      } else if (message->type() == LevelFinishedMessage::type_id()) {
        handle_level_finished(dynamic_cast<LevelFinishedMessage *>(message));
      } else if (message->type() == GameFinishedMessage::type_id()) {
        handle_game_finished(dynamic_cast<GameFinishedMessage *>(message));
      } else {
        std::stringstream ss;
        ss << std::hex
           << "Unexpected message in the RemoteServerProxyUpdater main loop with type 0x"
           << static_cast<int>(message->type());
        delete message;
        Logger::warning(ss.str());
        shutdown();
      }
      delete message;
    } catch (const InvalidMessageException& e) {
      std::stringstream ss;
      ss << "Unexpected message in the RemoteServerProxyUpdater main loop. "
         << e.what();
      Logger::error(ss.str());
      shutdown();
    }
  }
}
コード例 #2
0
ファイル: CuttingPlane.cpp プロジェクト: nixz/covise
//======================================================================
// Computation routine (called when START message arrrives)
//======================================================================
void Application::compute(void *)
{

    coDistributedObject *mesh;
    coDistributedObject *data;
    char *gname;
    char *dname;

    //	get parameter
    Covise::get_slider_param("i_index", &i_fro_min, &i_fro_max, &i_index);
    Covise::get_slider_param("j_index", &j_fro_min, &j_fro_max, &j_index);
    Covise::get_slider_param("k_index", &k_fro_min, &k_fro_max, &k_index);
    Covise::get_choice_param("plane", &plane);

    //	get input data object names
    gname = Covise::get_object_name("meshIn");
    if (gname == 0L)
    {
        Covise::sendError("ERROR: Object name not correct for 'Mesh'");
        return;
    }
    //	retrieve object from shared memeory
    mesh = new coDistributedObject(gname);

    //	get input data object names
    dname = Covise::get_object_name("dataIn");
    if (dname == 0L)
    {
        Covise::sendError("ERROR: Object name not correct for 'dataIn'");
        return;
    }
    //	retrieve object from shared memeory
    data = new coDistributedObject(dname);

    //	get output grid object names
    gname = Covise::get_object_name("meshOut");

    //	get output data object names
    dname = Covise::get_object_name("dataOut");

    handle_objects(mesh->createUnknown(), data->createUnknown(), gname, dname);
}
コード例 #3
0
ファイル: CuttingPlane.cpp プロジェクト: nixz/covise
void Application::handle_objects(coDistributedObject *mesh, coDistributedObject *data, char *Outgridname, char *Outdataname, coDistributedObject **mesh_set_out, coDistributedObject **data_set_out)
{
    coDoSet *D_set;
    coDoSet *G_set;
    coDistributedObject **grid_set_objs;
    coDistributedObject **data_set_objs;
    int i, set_num_elem;
    coDistributedObject **mesh_objs;
    coDistributedObject **data_objs;
    coDistributedObject *data_out;
    coDistributedObject *mesh_out;
    char buf[500];
    char buf2[500];
    char *dataType;

    if (mesh != 0L)
    {
        gtype = dataType = mesh->get_type();

        if (strcmp(gtype, "STRGRD") == 0)
        {
            s_grid_in = (coDoStructuredGrid *)mesh;
            s_grid_in->getGridSize(&i_dim, &j_dim, &k_dim);
            s_grid_in->getAddresses(&x_in, &y_in, &z_in);
        }

        else if (strcmp(gtype, "RCTGRD") == 0)
        {
            r_grid_in = (coDoRectilinearGrid *)mesh;
            r_grid_in->getGridSize(&i_dim, &j_dim, &k_dim);
            r_grid_in->getAddresses(&x_in, &y_in, &z_in);
        }

        else if (strcmp(gtype, "UNIGRD") == 0)
        {
            u_grid_in = (coDoUniformGrid *)mesh;
            u_grid_in->getGridSize(&i_dim, &j_dim, &k_dim);
        }
        dtype = data->get_type();
        if (strcmp(dtype, "STRSDT") == 0)
        {
            s_data_in = (coDoFloat *)data;
            s_data_in->getGridSize(&isize, &jsize, &ksize);
            s_data_in->getAddress(&s_in);
        }

        else if (strcmp(dtype, "STRVDT") == 0)
        {
            v_data_in = (coDoVec3 *)data;
            v_data_in->getGridSize(&isize, &jsize, &ksize);
            v_data_in->getAddresses(&u_in, &v_in, &w_in);
        }
        else if (strcmp(dataType, "SETELE") == 0)
        {
            mesh_objs = ((coDoSet *)mesh)->getAllElements(&set_num_elem);
            data_objs = ((coDoSet *)data)->getAllElements(&set_num_elem);
            grid_set_objs = new coDistributedObject *[set_num_elem];
            data_set_objs = new coDistributedObject *[set_num_elem];
            grid_set_objs[0] = NULL;
            data_set_objs[0] = NULL;
            for (i = 0; i < set_num_elem; i++)
            {
                sprintf(buf, "%s_%d", Outgridname, i);
                sprintf(buf2, "%s_%d", Outdataname, i);
                handle_objects(mesh_objs[i], data_objs[i], buf, buf2, grid_set_objs, data_set_objs);
            }
            G_set = new coDoSet(Outgridname, grid_set_objs);
            D_set = new coDoSet(Outdataname, data_set_objs);
            if (mesh->get_attribute("TIMESTEP"))
            {
                G_set->addAttribute("TIMESTEP", "1 16");
            }
            if (data->get_attribute("TIMESTEP"))
            {
                D_set->addAttribute("TIMESTEP", "1 16");
            }

            if (mesh_set_out)
            {
                for (i = 0; mesh_set_out[i]; i++)
                    ;

                mesh_set_out[i] = G_set;
                mesh_set_out[i + 1] = NULL;
            }
            else
                delete G_set;
            if (data_set_out)
            {
                for (i = 0; data_set_out[i]; i++)
                    ;

                data_set_out[i] = D_set;
                data_set_out[i + 1] = NULL;
            }
            else
                delete D_set;

            delete ((coDoSet *)mesh);
            delete ((coDoSet *)data);
            for (i = 0; data_set_objs[i]; i++)
                delete data_set_objs[i];
            delete[] data_set_objs;
            for (i = 0; grid_set_objs[i]; i++)
                delete grid_set_objs[i];
            delete[] grid_set_objs;
            return;
        }

        else
        {
            Covise::sendError("ERROR: Data object 'Data' has wrong data type");
            return;
        }
    }
    else
    {
#ifndef TOLERANT
        Covise::sendError("ERROR: Data object 'Data' can't be accessed in shared memory");
#endif
        return;
    }
    // check slider parameter and update if necessary
    if (i_index > i_dim)
    {
        i_index = i_dim / 2;
        Covise::sendWarning("WARNING: i-index out of range,  set new one");
        Covise::update_slider_param("i_index", i_fro_min, i_fro_max, i_index);
    }
    if (i_fro_max > i_dim) // set i max to i dimension
    {
        i_fro_max = i_dim;
        Covise::sendWarning("WARNING: i-max out of range,  set new one");
        Covise::update_slider_param("i_index", i_fro_min, i_fro_max, i_index);
    }
    if (i_fro_min < 1) // set i min to 1
    {
        i_fro_min = 1;
        Covise::sendWarning("WARNING: i-min out of range,  set new one");
        Covise::update_slider_param("i_index", i_fro_min, i_fro_max, i_index);
    }
    if (i_fro_max < i_fro_min)
    {
        i_fro_min = 1;
        i_fro_max = i_dim;
        Covise::sendWarning("WARNING: i-max > i_min,  set new one");
        Covise::update_slider_param("i_index", i_fro_min, i_fro_max, i_index);
    }

    if (j_index > j_dim)
    {
        j_index = j_dim / 2;
        Covise::sendWarning("WARNING: j-index out of range,  set new one");
        Covise::update_slider_param("j_index", j_fro_min, j_fro_max, j_index);
    }
    if (j_fro_max > j_dim) // set j max to j dimension
    {
        j_fro_max = j_dim;
        Covise::sendWarning("WARNING: j-max out of range,  set new one");
        Covise::update_slider_param("j_index", j_fro_min, j_fro_max, j_index);
    }
    if (j_fro_min < 1) // set j min to 1
    {
        j_fro_min = 1;
        Covise::sendWarning("WARNING: j-min out of range,  set new one");
        Covise::update_slider_param("j_index", j_fro_min, j_fro_max, j_index);
    }
    if (j_fro_max < j_fro_min)
    {
        j_fro_min = 1;
        j_fro_max = j_dim;
        Covise::sendWarning("WARNING: j-max > j_min,  set new one");
        Covise::update_slider_param("j_index", j_fro_min, j_fro_max, j_index);
    }

    if (k_index > k_dim)
    {
        k_index = k_dim / 2;
        Covise::sendWarning("WARNING: k-index out of range,  set new one");
        Covise::update_slider_param("k_index", k_fro_min, k_fro_max, k_index);
    }
    if (k_fro_max > k_dim) // set k max to k dimension
    {
        k_fro_max = k_dim;
        Covise::sendWarning("WARNING: k-max out of range,  set new one");
        Covise::update_slider_param("k_index", k_fro_min, k_fro_max, k_index);
    }
    if (k_fro_min < 1) // set k min to 1
    {
        k_fro_min = 1;
        Covise::sendWarning("WARNING: k-min out of range,  set new one");
        Covise::update_slider_param("k_index", k_fro_min, k_fro_max, k_index);
    }
    if (k_fro_max < k_fro_min)
    {
        k_fro_min = 1;
        k_fro_max = k_dim;
        Covise::sendWarning("WARNING: k-max > k_min,  set new one");
        Covise::update_slider_param("k_index", k_fro_min, k_fro_max, k_index);
    }

    //
    //      generate the output data objects
    //
    GridOut = Outgridname;
    DataOut = Outdataname;
    if (strcmp(gtype, "STRGRD") == 0)
    {
        Application::create_strgrid_plane();
        mesh_out = s_grid_out;
    }

    else if (strcmp(gtype, "RCTGRD") == 0)
    {
        Application::create_rectgrid_plane();
        mesh_out = r_grid_out;
    }

    else
    {
        Application::create_unigrid_plane();
        mesh_out = u_grid_out;
    }

    if (DataOut != NULL)
    {
        if (strcmp(dtype, "STRSDT") == 0)
        {
            Application::create_scalar_plane();
            data_out = s_data_out;
        }

        else
        {
            Application::create_vector_plane();
            data_out = v_data_out;
        }
    }

    //
    //      add objects to set
    //
    if (mesh_set_out)
    {
        for (i = 0; mesh_set_out[i]; i++)
            ;

        mesh_set_out[i] = mesh_out;
        mesh_set_out[i + 1] = NULL;
    }
    else
        delete mesh_out;
    if (data_set_out)
    {
        for (i = 0; data_set_out[i]; i++)
            ;

        data_set_out[i] = data_out;
        data_set_out[i + 1] = NULL;
    }
    else
        delete data_out;
}
コード例 #4
0
ファイル: ColorEdit.cpp プロジェクト: xyuan/covise
void Application::handle_objects(coDistributedObject *data_obj, char *Outname, coDistributedObject **set_out)
{
    int i;
    int setFlag;
    int num;

    char buf[500];
    char colormap_buf[255];
    char *img_name;
    char **attr;
    char **setting;

    coDoSet *D_set;
    coDistributedObject **set_objs;
    int set_num_elem;
    coDistributedObject *const *data_objs;

    int *vertex_list;

    depth++; // recurrence depth

    if (data_obj != 0L)
    {
        // prepare colormap attribute for attachment
        strcpy(colormap_as_an_attribute, "");
        sprintf(colormap_buf, "%s\n%s\n%g\n%g\n%ld\n%d", Outname, annotation, min, max, (steps > 0) ? steps : ncolor, 0);
        strcat(colormap_as_an_attribute, colormap_buf);

        for (i = 0; i < ncolor; i++)
        {
            sprintf(colormap_buf, "\n%f\n%f\n%f", colormap[0][i], colormap[1][i], colormap[2][i]);
            strcat(colormap_as_an_attribute, colormap_buf);
        }

        // get all attributes
        num = data_obj->get_all_attributes(&attr, &setting);

        dataType = data_obj->getType();
        if (strcmp(dataType, "USTSDT") == 0)
        {
            u_data = (coDoFloat *)data_obj;
            npoint = u_data->getNumPoints();
            u_data->getAddress(&scalar);
        }

        else if (strcmp(dataType, "SETELE") == 0)
        {
            if (min == max)
                Covise::sendWarning("Min==Max in Set: no automatic setting!");

            data = (coDoSet *)data_obj;
            data_objs = ((coDoSet *)data_obj)->getAllElements(&set_num_elem);
            set_objs = new coDistributedObject *[set_num_elem + 1];
            set_objs[0] = NULL;
            if (depth == 1)
                setFlag = 0;
            else
                setFlag = 1;

            for (i = 0; i < set_num_elem; i++)
            {
                sprintf(buf, "%s_%d", Outname, i);
                handle_objects(data_objs[i], buf, set_objs);
            }

            D_set = new coDoSet(Outname, set_objs);
            // setting attributes
            if (num > 0)
                D_set->addAttributes(num, attr, setting);

            if (setFlag == 0)
            {
                D_set->addAttribute("COLORMAP", colormap_as_an_attribute);
            }

            if (set_out)
            {
                for (i = 0; set_out[i]; i++)
                    ;
                set_out[i] = D_set;
                set_out[i + 1] = NULL;
            }
            else
                delete D_set;
            delete ((coDoSet *)data_obj);
            for (i = 0; set_objs[i]; i++)
                delete set_objs[i];
            delete[] set_objs;
            return;
        }

        else
        {
            Covise::sendError("ERROR: Data object 'Data' has wrong data type");
            return;
        }
    }
    else
    {
#ifndef TOLERANT
        Covise::sendError("ERROR: Data object 'Data' can't be accessed in shared memory");
#else
        Covise::send_stop_pipeline();
#endif
        return;
    }

    /////////////////////////////////////////////////////////////////
    //      generate the output data objects

    if (map == 1 || npoint == 0) // rgba colors : always use rgba for empty obj
    {

        if (strcmp(dataType, "STRSDT") == 0)
        {
            p_colors = new coDoRGBA(Outname, i_dim * j_dim * k_dim);
            if (!p_colors->objectOk())
            {
                Covise::sendError("ERROR: creation of data object 'Colors' failed");
                return;
            }
            p_colors->getAddress(&pc);

            make_rgba_colors(scalar, npoint, (steps > 0) ? steps : ncolor, pc,
                             &colormap[0][0], &colormap[1][0],
                             &colormap[2][0], &colormap[3][0], min, max);

            // setting attributes
            if (num > 0)
                p_colors->addAttributes(num, attr, setting);
            if (depth == 1)
                p_colors->addAttribute("COLORMAP", colormap_as_an_attribute);
            delete s_data;
        }

        else if (strcmp(dataType, "USTSDT") == 0)
        {
            p_colors = new coDoRGBA(Outname, npoint);
            if (!p_colors->objectOk())
            {
                Covise::sendError("ERROR: creation of data object 'Colors' failed");
                return;
            }
            p_colors->getAddress(&pc);

            make_rgba_colors(scalar, npoint, (steps > 0) ? steps : ncolor, pc,
                             &colormap[0][0], &colormap[1][0],
                             &colormap[2][0], &colormap[3][0], min, max);

            // setting attributes
            if (num > 0)
                p_colors->addAttributes(num, attr, setting);
            if (depth == 1)
                p_colors->addAttribute("COLORMAP", colormap_as_an_attribute);
            delete u_data;
        }
    }

    else if (map == 2) // texture coordinates
    {
        // simple vertex_list
        vertex_list = new int[npoint];
        for (i = 0; i < npoint; i++)
            vertex_list[i] = i;

        // allocate tex_coords
        tex_coords = new float *[2];
        for (i = 0; i < 2; i++)
            tex_coords[i] = new float[npoint];
        // initialize y-component of texture coordinate
        for (i = 0; i < npoint; i++)
            tex_coords[1][i] = 0.0;

        make_texCoord(scalar, npoint, ncolor, min, max);

        img_name = new char[strlen(Outname) + 5];
        strcpy(img_name, Outname);
        strcat(img_name, "_Img");

        colorLUT = new coDoPixelImage(img_name, ncolor, 1,
                                      PIXEL_SIZE, PIXEL_FORMAT, image);

        p_texture = new coDoTexture(Outname, colorLUT, 0, 4, TEXTURE_LEVEL,
                                    npoint, vertex_list, npoint, tex_coords);

        // setting attributes
        if (num > 0)
            p_texture->addAttributes(num, attr, setting);
        // set the colormap attribute
        if (depth == 1)
            p_texture->addAttribute("COLORMAP", colormap_as_an_attribute);

        //free
        delete[] vertex_list;
        delete[] tex_coords[0];
        delete[] tex_coords[1];
        delete[] tex_coords;
    }

    //      add objects to set
    if (set_out)
    {
        for (i = 0; set_out[i]; i++)
            ;

        if (map == 1)
            set_out[i] = p_colors;
        else if (map == 2)
            set_out[i] = p_texture;
        set_out[i + 1] = NULL;
    }
    else
    {
        //delete p_colors;
        //delete p_texture;
        //delete colorLUT;
    }
}
コード例 #5
0
ファイル: ColorEdit.cpp プロジェクト: xyuan/covise
//======================================================================
// Computation routine (called when START message arrrives)
//======================================================================
void Application::compute(void *)
{
    int i, j;
    //float my_min,my_max;
    char *MinMax_Name;
    float *s;
    // restore map after interpolation
    float restore[5][COLORMAP_WIDTH];

    coDoFloat *minmax_data = NULL;

    depth = 0;

    Covise::get_choice_param("Map", &map);
    // min and max saved in param
    Covise::get_string_param("Annotation", &annotation);
    Covise::get_scalar_param("Steps", &steps);

    if (annotation == NULL)
        annotation = annotation_default;
    /*************
      if ( my_min == 0.0 && my_max == 0.0 )
      {
         // use min,max given in param routine already from color editor
         // error = Covise::get_colormap_param("colormap",&min,&max,&ncolor);
      }
      else
      { // use min,max given in user interface of this module
         min = my_min;
         max = my_max;
      }
   **************/
    // an explicit module connection overrides min, max given so far
    MinMax_Name = Covise::get_object_name("minmax");
    if (MinMax_Name == 0L)
    {
        // ignore
    }
    else // get min, max from another module
    {
        minmax_data = new coDoFloat(MinMax_Name);
        if ((minmax_data == NULL) || (!(minmax_data->objectOk())))
        {
#ifndef TOLERANT
            Covise::sendError("ERROR: Data object 'Data' can't be accessed in shared memory");
#else
            Covise::send_stop_pipeline();
#endif
            return;
        }
        minmax_data->getAddress(&s);
        min = s[0];
        max = s[1];
    }

    if (steps > 0)
    {
        // transform map into color-ramps

        float map[4][COLORMAP_WIDTH];
        for (i = 0; i < 4; i++)
        {
            for (j = 0; j < COLORMAP_WIDTH; j++)
            {
                restore[i][j] = map[i][j] = colormap[i][j];
            }
        }
        // interpolate colormap
        double delta = 1.0 / (steps - 1) * (ncolor - 1);

        for (i = 0; i < steps - 1; i++)
        {
            double x = i * delta;
            int idx = (int)x;
            double d = x - idx;
            colormap[0][i] = (1 - d) * map[0][idx] + d * map[0][idx + 1];
            colormap[1][i] = (1 - d) * map[1][idx] + d * map[1][idx + 1];
            colormap[2][i] = (1 - d) * map[2][idx] + d * map[2][idx + 1];
            colormap[3][i] = (1 - d) * map[3][idx] + d * map[3][idx + 1];
            //colormap[i][4] = -1;
        }
        colormap[0][steps - 1] = map[0][ncolor - 1];
        colormap[1][steps - 1] = map[1][ncolor - 1];
        colormap[2][steps - 1] = map[2][ncolor - 1];
        colormap[3][steps - 1] = map[3][ncolor - 1];
        //colormap[steps-1][4] = -1;
    }

    // generate pixel-image
    image = new char[ncolor * 4];
    for (i = 0; i < ncolor; i++)
    {
        image[i * 4] = (unsigned char)(255.0 * colormap[0][i] + 0.5);
        image[i * 4 + 1] = (unsigned char)(255.0 * colormap[1][i] + 0.5);
        image[i * 4 + 2] = (unsigned char)(255.0 * colormap[2][i] + 0.5);
        image[i * 4 + 3] = (unsigned char)(255.0 * colormap[3][i] + 0.5);
    }

    //	get input data object names
    Data = Covise::get_object_name("Data");
    if (Data == 0L)
    {
        Covise::sendError("ERROR: Object name not correct for 'Data'");
        return;
    }

    //	get output data object	names
    Colors = Covise::get_object_name("Colors");
    if (Colors == 0L)
    {
        Covise::sendError("ERROR: Object name not correct for 'Colors'");
        return;
    }

    //	retrieve object from shared memeory
    tmp_obj = new coDistributedObject(Data);
    data_obj = tmp_obj->createUnknown();
    handle_objects(tmp_obj->createUnknown(), Colors);

    if (steps > 0)
    {
        // undo interpolation
        for (i = 0; i < 4; i++)
        {
            for (j = 0; j < COLORMAP_WIDTH; j++)
            {
                colormap[i][j] = restore[i][j];
            }
        }
    }

    // free
    delete[] image;
    delete tmp_obj;
}