void GCoptimization::commonNonGridInitialization(PixelType nupixels, int num_labels) { terminateOnError( (nupixels <0) || (num_labels <0 ),"Illegal negative parameters"); m_nLabels = num_labels; m_nPixels = nupixels; m_grid_graph = 0; m_neighbors = (LinkedBlockList *) new LinkedBlockList[nupixels]; terminateOnError(!m_neighbors,"Not enough memory"); }
GCoptimization::EnergyType Swap::alpha_beta_swap(LabelType alpha_label, LabelType beta_label) { terminateOnError( alpha_label < 0 || alpha_label >= m_nLabels || beta_label < 0 || beta_label >= m_nLabels, "Illegal Label to Expand On"); perform_alpha_beta_swap(alpha_label,beta_label); return(dataEnergy()+smoothnessEnergy()); }
GCoptimization::EnergyType Expansion::oneExpansionIteration() { int next; terminateOnError( m_dataType == NONE,"You have to set up the data cost before running optimization"); terminateOnError( m_smoothType == NONE,"You have to set up the smoothness cost before running optimization"); if (m_random_label_order) scramble_label_table(); for (next = 0; next < m_nLabels; next++ ) perform_alpha_expansion(m_labelTable[next]); return(dataEnergy()+smoothnessEnergy()); }
GCoptimization::EnergyType Expansion::alpha_expansion(LabelType label) { terminateOnError( label < 0 || label >= m_nLabels,"Illegal Label to Expand On"); perform_alpha_expansion(label); return(dataEnergy()+smoothnessEnergy()); }
int main(int argc, char** argv) { DBusConnection* bus = NULL; DBusMessage* msg = NULL; DBusError error; DBusPendingCall* pending; dbus_error_init(&error); printf("Connecting to Session D-Bus\n"); bus = dbus_bus_get(DBUS_BUS_SESSION, &error); terminateOnError("Failed to open Session bus\n", &error); assert(bus != NULL); printf("Creating a message object\n"); msg = dbus_message_new_method_call( NOTIFY_TARGET, NOTIFY_OBJ_PATH, NOTIFY_INTERFACE, NOTIFY_METHOD); assert(msg != NULL); printf("Appending arguments to the message\n"); fillArgs(msg); #ifndef WAIT_FOR_REPLY dbus_message_set_no_reply(msg, TRUE); printf("Adding message to client send-queue\n"); dbus_connection_send(bus, msg, NULL); printf("Waiting for send-queue to be send out\n"); dbus_connection_flush(bus); printf("Cleaning up message\n"); dbus_message_unref(msg); #else printf("Adding message to client send-queue\n"); dbus_connection_send_with_reply(bus, msg, &pending, -1); printf("Waiting for send-queue to be send out\n"); dbus_connection_flush(bus); printf("Cleaning up message\n"); dbus_message_unref(msg); recvReply(pending); #endif printf("Cleaning up connection\n"); dbus_connection_unref(bus); return 0; }
/* Use this constructor only for grid graphs */ GCoptimization::GCoptimization(PixelType width,PixelType height,LabelType nLabels,EnergyFunction *eng):MRF(width,height,nLabels,eng) { commonGridInitialization(width,height,nLabels); m_labeling = (LabelType *) new LabelType[m_nPixels]; terminateOnError(!m_labeling,"out of memory"); for ( int i = 0; i < m_nPixels; i++ ) m_labeling[i] = (LabelType) 0; commonInitialization(); }
void GCoptimization::initialize_memory() { m_lookupPixVar = (PixelType *) new PixelType[m_nPixels]; m_labelTable = (LabelType *) new LabelType[m_nLabels]; terminateOnError( !m_lookupPixVar || !m_labelTable ,"Not enough memory"); for ( int i = 0; i < m_nLabels; i++ ) m_labelTable[i] = i; }
void GCoptimization::commonGridInitialization(PixelType width, PixelType height, int nLabels) { terminateOnError( (width < 0) || (height <0) || (nLabels <0 ),"Illegal negative parameters"); m_width = width; m_height = height; m_nPixels = width*height; m_nLabels = nLabels; m_grid_graph = 1; }
static DBusHandlerResult signal_filter (DBusConnection *connection, DBusMessage *message, void *user_data) {/*类似一个侦听函数,收到的消息在message中*/ GMainLoop *loop = user_data; /*一个断开连接的信号*/ if(dbus_message_is_signal(message, DBUS_INTERFACE_LOCAL, "Disconnected")) { /*终止循环*/ g_print("receive quit signal"); g_main_loop_quit (loop); return DBUS_HANDLER_RESULT_HANDLED; } /*接收到调用print函数的消息*/ else if (dbus_message_is_method_call(message, "org.freedesktop.program2", "print")) { DBusError error; char *s; dbus_error_init (&error); /*获得参数*/ if (dbus_message_get_args (message, &error, DBUS_TYPE_STRING, &s, DBUS_TYPE_INVALID)) { g_print("received args: %s\n", s); /*难道远程调用只能这样调用么?*/ print(s); /*此处如果释放则会出现异常所以暂时就不释放了!*/ //dbus_free (s); } else { g_print("received, but error getting message: %s\n", error.message); terminateOnError (" received, but error getting message\n", & error ); dbus_error_free (&error); } return DBUS_HANDLER_RESULT_HANDLED; } return DBUS_HANDLER_RESULT_NOT_YET_HANDLED; }
Swap::Swap(PixelType nPixels, int num_labels, EnergyFunction *eng):GCoptimization(nPixels,num_labels,eng) { m_pixels = new PixelType[m_nPixels]; terminateOnError( !m_pixels ,"Not enough memory"); }